mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Add scenario one file pointing to root file
Add scenario one file pointing to root file
This commit is contained in:
committed by
Erik Mendoza
parent
2312dccd74
commit
2fea161d84
@@ -50,6 +50,16 @@ function getReferences (currentNode) {
|
||||
return referencesInNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a referenced node from the data input by path
|
||||
* @param {string} path1 - path1 to compare
|
||||
* @param {string} path2 - path2 to compare
|
||||
* @returns {boolean} - wheter is the same path
|
||||
*/
|
||||
function comparePaths(path1, path2) {
|
||||
return path1 === path2; // todo change this comparision
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a referenced node from the data input by path
|
||||
* @param {string} referencePath - value from the $ref property
|
||||
@@ -58,7 +68,7 @@ function getReferences (currentNode) {
|
||||
*/
|
||||
function findNodeFromPath(referencePath, allData) {
|
||||
return allData.find((node) => {
|
||||
return node.fileName === referencePath; // todo change this comparision
|
||||
return comparePaths(node.fileName, referencePath);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -66,9 +76,10 @@ function findNodeFromPath(referencePath, allData) {
|
||||
* Maps the output from get root files to detect root files
|
||||
* @param {object} currentNode - current { path, content} object
|
||||
* @param {Array} allData - array of { path, content} objects
|
||||
* @param {object} specRoot - root file information
|
||||
* @returns {object} - Detect root files result object
|
||||
*/
|
||||
function getAdjacentAndMissing (currentNode, allData) {
|
||||
function getAdjacentAndMissing (currentNode, allData, specRoot) {
|
||||
let currentNodeReferences = getReferences(currentNode),
|
||||
graphAdj = [],
|
||||
missingNodes = [];
|
||||
@@ -77,9 +88,10 @@ function getAdjacentAndMissing (currentNode, allData) {
|
||||
let referencePath = reference.path,
|
||||
adjacentNode = findNodeFromPath(referencePath, allData);
|
||||
if (adjacentNode) {
|
||||
adjacentNode.relativeToRootPath = referencePath;
|
||||
graphAdj.push(adjacentNode);
|
||||
}
|
||||
else {
|
||||
else if (!comparePaths(referencePath, specRoot.path)) {
|
||||
missingNodes.push({ relativeToRootPath: referencePath });
|
||||
}
|
||||
});
|
||||
@@ -97,8 +109,16 @@ module.exports = {
|
||||
getRelatedFiles: function (specRoot, allData) {
|
||||
let algorithm = new DFS(),
|
||||
{ traverseOrder, missing } =
|
||||
algorithm.traverse(specRoot, (currentNode) => { return getAdjacentAndMissing(currentNode, allData); });
|
||||
return { relatedFiles: traverseOrder.slice(1), missingRelatedFiles: missing };
|
||||
algorithm.traverse(specRoot, (currentNode) => {
|
||||
return getAdjacentAndMissing(currentNode, allData, specRoot);
|
||||
}),
|
||||
outputRelatedFiles = traverseOrder.slice(1).map((relatedFile) => {
|
||||
return {
|
||||
relativeToRootPath: relatedFile.relativeToRootPath,
|
||||
path: relatedFile.fileName
|
||||
};
|
||||
});
|
||||
return { relatedFiles: outputRelatedFiles, missingRelatedFiles: missing };
|
||||
},
|
||||
getReferences,
|
||||
getAdjacentAndMissing
|
||||
|
||||
Reference in New Issue
Block a user