UNPKG

openapi-modifier

Version:

This package allows you to automate the process of modifying OpenAPI specifications by applying a set of predefined rules

59 lines (58 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const object_path_1 = require("./object-path"); describe('getPathKeys', () => { test.each([ ['', []], ['foo', ['foo']], ['foo.bar', ['foo', 'bar']], ['foo.1.bar', ['foo', '1', 'bar']], ['foo.[1].bar', ['foo', '1', 'bar']], ['foo[1].bar', ['foo', '1', 'bar']], ['[].bar', ['bar']], ])('getPathKeys(%s)', (schema, expectedResult) => { expect((0, object_path_1.getPathKeys)(schema)).toEqual(expectedResult); }); }); describe('getObjectPath', () => { test('regular, string path', () => { const result = (0, object_path_1.getObjectPath)({ foo: { bar: { test: 1, } } }, 'foo.bar.test'); expect(result).toEqual(1); }); test('regular, array path', () => { const result = (0, object_path_1.getObjectPath)({ foo: { bar: { test: 1, } } }, ['foo', 'bar', 'test']); expect(result).toEqual(1); }); test('with array, string path', () => { const result = (0, object_path_1.getObjectPath)({ foo: { bar: [{}, { test: 1, }] } }, 'foo.bar[1].test'); expect(result).toEqual(1); }); test('with array, array path', () => { const result = (0, object_path_1.getObjectPath)({ foo: { bar: [{}, { test: 1, }] } }, ['foo', 'bar', '1', 'test']); expect(result).toEqual(1); }); });