mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Filter roots by specification version
Filter roots by specification version
This commit is contained in:
committed by
Erik Mendoza
parent
e040455f46
commit
f3030247ea
@@ -68,8 +68,14 @@ function added(path, referencesInNode) {
|
|||||||
*/
|
*/
|
||||||
function getReferences (currentNode) {
|
function getReferences (currentNode) {
|
||||||
let referencesInNode = [],
|
let referencesInNode = [],
|
||||||
currentContent = currentNode.content;
|
currentContent = currentNode.content,
|
||||||
const OASObject = parse.getOasObject(currentContent);
|
OASObject;
|
||||||
|
if (currentNode.parsed) {
|
||||||
|
OASObject = currentNode.parsed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
OASObject = parse.getOasObject(currentContent);
|
||||||
|
}
|
||||||
traverseUtility(OASObject).forEach((property) => {
|
traverseUtility(OASObject).forEach((property) => {
|
||||||
if (property) {
|
if (property) {
|
||||||
let hasReferenceTypeKey;
|
let hasReferenceTypeKey;
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ const { formatDataPath, checkIsCorrectType, isKnownType,
|
|||||||
|
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto'),
|
||||||
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
|
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
|
||||||
{ getRelatedFiles } = require('./relatedFiles');
|
{ getRelatedFiles } = require('./relatedFiles'),
|
||||||
|
{ compareVersion } = require('./common/versionUtils.js'),
|
||||||
|
parse = require('./parse');
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
// See https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options
|
// See https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options
|
||||||
@@ -4852,17 +4854,25 @@ module.exports = {
|
|||||||
* @param {object} rootFiles - rootFile:{path:string}
|
* @param {object} rootFiles - rootFile:{path:string}
|
||||||
* @param {array} inputData - [{path:string}]}
|
* @param {array} inputData - [{path:string}]}
|
||||||
* @param {string} origin - process origin
|
* @param {string} origin - process origin
|
||||||
|
* @param {string} version - process specification version
|
||||||
*
|
*
|
||||||
* @returns {object} root files information and data input
|
* @returns {object} root files information and data input
|
||||||
*/
|
*/
|
||||||
mapProcessRelatedFiles(rootFiles, inputData, origin) {
|
mapProcessRelatedFiles(rootFiles, inputData, origin, version) {
|
||||||
let data = rootFiles.map((root) => {
|
let parsedRootFiles = rootFiles.map((rootFile) => {
|
||||||
let { relatedFiles, missingRelatedFiles } = getRelatedFiles(root, inputData, origin);
|
let parsedContent = parse.getOasObject(rootFile.content);
|
||||||
return {
|
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
|
||||||
rootFile: { path: root.fileName },
|
}).filter((rootWithParsedContent) => {
|
||||||
relatedFiles,
|
return compareVersion(version, rootWithParsedContent.parsed.oasObject.openapi);
|
||||||
missingRelatedFiles };
|
}),
|
||||||
});
|
data = parsedRootFiles.map((root) => {
|
||||||
|
let { relatedFiles, missingRelatedFiles } = getRelatedFiles(root, inputData, origin);
|
||||||
|
return {
|
||||||
|
rootFile: { path: root.fileName },
|
||||||
|
relatedFiles,
|
||||||
|
missingRelatedFiles
|
||||||
|
};
|
||||||
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -4890,7 +4900,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
if (inputRelatedFiles.rootFiles && inputRelatedFiles.rootFiles.length > 0) {
|
if (inputRelatedFiles.rootFiles && inputRelatedFiles.rootFiles.length > 0) {
|
||||||
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
|
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
|
||||||
inputRelatedFiles.origin);
|
inputRelatedFiles.origin, version);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ let expect = require('chai').expect,
|
|||||||
PET_STORE_SEPARATED = '../data/petstore separate yaml/spec',
|
PET_STORE_SEPARATED = '../data/petstore separate yaml/spec',
|
||||||
RELATED_FILES = '../data/relatedFiles',
|
RELATED_FILES = '../data/relatedFiles',
|
||||||
PET_STORE_SEPARATED_COMMON = '../data/petstore separate yaml/common',
|
PET_STORE_SEPARATED_COMMON = '../data/petstore separate yaml/common',
|
||||||
|
VALID_OPENAPI_31_PATH = '../data/valid_openapi31X',
|
||||||
validPetstore = path.join(__dirname, VALID_OPENAPI_PATH + '/petstore.yaml'),
|
validPetstore = path.join(__dirname, VALID_OPENAPI_PATH + '/petstore.yaml'),
|
||||||
petstoreSeparatedPet = path.join(__dirname, PET_STORE_SEPARATED + '/Pet.yaml'),
|
petstoreSeparatedPet = path.join(__dirname, PET_STORE_SEPARATED + '/Pet.yaml'),
|
||||||
petstoreSeparatedError = path.join(__dirname, PET_STORE_SEPARATED_COMMON + '/Error.yaml'),
|
petstoreSeparatedError = path.join(__dirname, PET_STORE_SEPARATED_COMMON + '/Error.yaml'),
|
||||||
@@ -18,10 +19,8 @@ let expect = require('chai').expect,
|
|||||||
internalRefOnly = path.join(__dirname, VALID_OPENAPI_PATH + '/deepObjectLengthProperty.yaml'),
|
internalRefOnly = path.join(__dirname, VALID_OPENAPI_PATH + '/deepObjectLengthProperty.yaml'),
|
||||||
circularRef = path.join(__dirname, RELATED_FILES + '/circularRef.yaml'),
|
circularRef = path.join(__dirname, RELATED_FILES + '/circularRef.yaml'),
|
||||||
oldPet = path.join(__dirname, RELATED_FILES + '/oldPet.yaml'),
|
oldPet = path.join(__dirname, RELATED_FILES + '/oldPet.yaml'),
|
||||||
pet = path.join(__dirname, RELATED_FILES + '/Pet.yaml');
|
pet = path.join(__dirname, RELATED_FILES + '/Pet.yaml'),
|
||||||
// petstoreSeparatedJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/swagger.json'),
|
validHopService31x = path.join(__dirname, VALID_OPENAPI_31_PATH + '/yaml/hopService.yaml');
|
||||||
// petstoreSeparatedPetJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/Pet.json'),
|
|
||||||
// validHopService31x = path.join(__dirname, VALID_OPENAPI_31_PATH + '/yaml/hopService.yaml');
|
|
||||||
|
|
||||||
describe('detectRelatedFiles method', function() {
|
describe('detectRelatedFiles method', function() {
|
||||||
|
|
||||||
@@ -220,4 +219,52 @@ describe('detectRelatedFiles method', function() {
|
|||||||
expect(res.output.data[0].relatedFiles.length).to.equal(4);
|
expect(res.output.data[0].relatedFiles.length).to.equal(4);
|
||||||
expect(res.output.data[0].missingRelatedFiles.length).to.equal(0);
|
expect(res.output.data[0].missingRelatedFiles.length).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should filter root according to the version 3.1', async function() {
|
||||||
|
let contentFilePet = fs.readFileSync(validPetstore, 'utf8'),
|
||||||
|
contentFileHop = fs.readFileSync(validHopService31x, 'utf8'),
|
||||||
|
input = {
|
||||||
|
type: 'folder',
|
||||||
|
specificationVersion: '3.1',
|
||||||
|
rootFiles: [
|
||||||
|
{
|
||||||
|
path: '/petstore.yaml',
|
||||||
|
content: contentFilePet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/hopService.yaml',
|
||||||
|
content: contentFileHop
|
||||||
|
}
|
||||||
|
],
|
||||||
|
data: [
|
||||||
|
]
|
||||||
|
};
|
||||||
|
const res = await Converter.detectRelatedFiles(input);
|
||||||
|
expect(res).to.not.be.empty;
|
||||||
|
expect(res.result).to.be.true;
|
||||||
|
expect(res.output.data[0].rootFile.path).to.equal('/hopService.yaml');
|
||||||
|
});
|
||||||
|
it('should filter root according to the version default', async function() {
|
||||||
|
let contentFilePet = fs.readFileSync(validPetstore, 'utf8'),
|
||||||
|
contentFileHop = fs.readFileSync(validHopService31x, 'utf8'),
|
||||||
|
input = {
|
||||||
|
type: 'folder',
|
||||||
|
rootFiles: [
|
||||||
|
{
|
||||||
|
path: '/petstore.yaml',
|
||||||
|
content: contentFilePet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/hopService.yaml',
|
||||||
|
content: contentFileHop
|
||||||
|
}
|
||||||
|
],
|
||||||
|
data: [
|
||||||
|
]
|
||||||
|
};
|
||||||
|
const res = await Converter.detectRelatedFiles(input);
|
||||||
|
expect(res).to.not.be.empty;
|
||||||
|
expect(res.result).to.be.true;
|
||||||
|
expect(res.output.data[0].rootFile.path).to.equal('/petstore.yaml');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user