mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Avoid reporting local refs
Avoid reporting local refs
This commit is contained in:
committed by
Erik Mendoza
parent
2fea161d84
commit
4a38a70d0b
@@ -8,8 +8,11 @@ const traverseUtility = require('traverse'),
|
||||
* @param {string} key - specified version of the process
|
||||
* @returns {object} - Detect root files result object
|
||||
*/
|
||||
function isRef(obj, key) {
|
||||
return key === '$ref' && typeof obj[key] === 'string' && obj[key] !== undefined;
|
||||
function isExtRef(obj, key) {
|
||||
return key === '$ref' &&
|
||||
typeof obj[key] === 'string' &&
|
||||
obj[key] !== undefined &&
|
||||
!obj[key].startsWith('#');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +40,7 @@ function getReferences (currentNode) {
|
||||
hasReferenceTypeKey = Object.keys(property)
|
||||
.find(
|
||||
(key) => {
|
||||
return isRef(property, key);
|
||||
return isExtRef(property, key);
|
||||
}
|
||||
);
|
||||
if (hasReferenceTypeKey) {
|
||||
|
||||
@@ -13,7 +13,8 @@ var expect = require('chai').expect,
|
||||
petstoreSeparatedPet = path.join(__dirname, PET_STORE_SEPARATED + '/Pet.yaml'),
|
||||
missedRef = path.join(__dirname, RELATED_FILES + '/missedRef.yaml'),
|
||||
circularRefNewPet = path.join(__dirname, RELATED_FILES + '/NewPet.yaml'),
|
||||
refToRoot = path.join(__dirname, RELATED_FILES + '/refToRoot.yaml');
|
||||
refToRoot = path.join(__dirname, RELATED_FILES + '/refToRoot.yaml'),
|
||||
internalRefOnly = path.join(__dirname, VALID_OPENAPI_PATH + '/deepObjectLengthProperty.yaml');
|
||||
// petstoreSeparatedJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/swagger.json'),
|
||||
// petstoreSeparatedPetJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/Pet.json'),
|
||||
// validHopService31x = path.join(__dirname, VALID_OPENAPI_31_PATH + '/yaml/hopService.yaml');
|
||||
@@ -117,4 +118,27 @@ describe('detectRoot method', function() {
|
||||
expect(res.output.data[0].missingRelatedFiles[0].relativeToRootPath).to.equal('Pet.yaml');
|
||||
|
||||
});
|
||||
|
||||
it('should not return local ref as missing node', async function () {
|
||||
const contentFileMissedRef = fs.readFileSync(internalRefOnly, 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '3.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/deepObjectLengthProperty.yaml',
|
||||
content: contentFileMissedRef
|
||||
}
|
||||
],
|
||||
data: [
|
||||
]
|
||||
},
|
||||
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('/deepObjectLengthProperty.yaml');
|
||||
expect(res.output.data[0].relatedFiles.length).to.equal(0);
|
||||
expect(res.output.data[0].missingRelatedFiles.length).to.equal(0);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,10 +4,12 @@ const { getRelatedFiles, getReferences, getAdjacentAndMissing } = require('./../
|
||||
path = require('path'),
|
||||
PET_STORE_SEPARATED = '../data/petstore separate yaml/spec',
|
||||
RELATED_FILES = '../data/relatedFiles',
|
||||
VALID_OPENAPI_PATH = '../data/valid_openapi',
|
||||
newPet = path.join(__dirname, PET_STORE_SEPARATED + '/NewPet.yaml'),
|
||||
swaggerRoot = path.join(__dirname, PET_STORE_SEPARATED + '/swagger.yaml'),
|
||||
petstoreSeparatedPet = path.join(__dirname, PET_STORE_SEPARATED + '/Pet.yaml'),
|
||||
missedRef = path.join(__dirname, RELATED_FILES + '/missedRef.yaml');
|
||||
missedRef = path.join(__dirname, RELATED_FILES + '/missedRef.yaml'),
|
||||
internalRefOnly = path.join(__dirname, VALID_OPENAPI_PATH + '/deepObjectLengthProperty.yaml');
|
||||
|
||||
|
||||
describe('getAdjacentAndMissing function', function () {
|
||||
@@ -101,4 +103,16 @@ describe('getRelatedFiles function ', function () {
|
||||
|
||||
});
|
||||
|
||||
it('should not return internal refs as missing ref', function () {
|
||||
const contentFile = fs.readFileSync(internalRefOnly, 'utf8'),
|
||||
rootNode = {
|
||||
fileName: '/deepObjectLengthProperty.yaml',
|
||||
content: contentFile
|
||||
},
|
||||
inputData = [],
|
||||
{ relatedFiles, missingRelatedFiles } = getRelatedFiles(rootNode, inputData);
|
||||
expect(relatedFiles.length).to.equal(0);
|
||||
expect(missingRelatedFiles.length).to.equal(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user