mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Changing the way the object keys are generated
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
|
||||
const expect = require('chai').expect,
|
||||
{ jsonPointerEncodeAndReplace,
|
||||
{
|
||||
getJsonPointerRelationToRoot,
|
||||
concatJsonPointer,
|
||||
getKeyInComponents } = require('./../../lib/jsonPointer');
|
||||
getKeyInComponents
|
||||
} = require('./../../lib/jsonPointer');
|
||||
|
||||
describe('getKeyInComponents function', function () {
|
||||
it('should return [] when is pointing to an element in components', function () {
|
||||
@@ -17,10 +18,42 @@ describe('getKeyInComponents function', function () {
|
||||
expect(result).to.be.an('array').with.length(0);
|
||||
});
|
||||
|
||||
it('should return ["schemas", "folder/pet.yaml"] when there is an scaped slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], 'folder~1pet.yaml');
|
||||
it('should return ["schemas", "_folder_pet.yaml"] when the filename scaped slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '~1folder~1pet.yaml');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml"] when the filename contains any slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder/pet.yaml');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml-_Name"] when the filename contains any sacped slash' +
|
||||
'and a local part using a scaped sharp', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '~1folder~1pet.yaml%23~1Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml-_Name');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml-_Name"] when the filename contains any slash' +
|
||||
'and a local part using a sharp', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder/pet.yaml#/Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml-_Name');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_foldertest_pet.yaml-_Name"] when the filename contains any slash' +
|
||||
'and a local part using a sharp and another not valid character', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder@test/pet@.yaml#/Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_foldertest_pet.yaml-_Name');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +61,6 @@ describe('getKeyInComponents function', function () {
|
||||
describe('getJsonPointerRelationToRoot function', function () {
|
||||
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'Pets.yaml',
|
||||
['schemas', 'Pets.yaml']
|
||||
);
|
||||
@@ -36,7 +68,6 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
});
|
||||
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'hello.yaml#/definitions/world',
|
||||
['schemas', 'hello.yaml']
|
||||
);
|
||||
@@ -44,7 +75,6 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
});
|
||||
it('should return "#/components/schemas/Error" no file path', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'#/components/schemas/Error',
|
||||
['components', 'schemas', 'Error']
|
||||
);
|
||||
@@ -55,45 +85,40 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
describe('concatJsonPointer function ', function () {
|
||||
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/Pets.yaml');
|
||||
});
|
||||
|
||||
it('should return "#/components/schemas/other~1Pets.yaml" no local path and schema folder in filename', function () {
|
||||
it('should return "#/components/schemas/other_Pets.yaml" no local path and schema folder in filename', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'other/Pets.yaml'],
|
||||
['schemas', 'other_Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/other~1Pets.yaml');
|
||||
expect(res).to.equal('#/components/schemas/other_Pets.yaml');
|
||||
});
|
||||
it('should return "#/components/schemas/some~1Pet" no local path and schema folder in filename', function () {
|
||||
it('should return "#/components/schemas/some_Pet" no local path and schema folder in filename', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'some/Pet.yaml'],
|
||||
['schemas', 'some_Pet.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/some~1Pet.yaml');
|
||||
expect(res).to.equal('#/components/schemas/some_Pet.yaml');
|
||||
});
|
||||
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'hello.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/hello.yaml');
|
||||
});
|
||||
|
||||
it('should return "#/components/schemas/~1Pets.yaml" no local path and schema', function () {
|
||||
it('should return "#/components/schemas/_Pets.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', '/Pets.yaml'],
|
||||
['schemas', '_Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/~1Pets.yaml');
|
||||
expect(res).to.equal('#/components/schemas/_Pets.yaml');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user