Skip to content

Commit

Permalink
Fixing issue #309
Browse files Browse the repository at this point in the history
  • Loading branch information
erfemega committed Nov 24, 2022
1 parent 74d831b commit 8619eff
Show file tree
Hide file tree
Showing 4 changed files with 1,405 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,24 @@ module.exports = {
return reqParam;
},

dereferenceFromOutOfComponents: function (spec, reference) {
let splitRef = reference.split('/'),
resolvedContent;

splitRef = splitRef.slice(1).map((elem) => {
// https://swagger.io/docs/specification/using-ref#escape
// since / is the default delimiter, slashes are escaped with ~1
return decodeURIComponent(
elem
.replace(/~1/g, '/')
.replace(/~0/g, '~')
);
});

resolvedContent = deref._getEscaped(spec, splitRef);
return resolvedContent;
},

/**
* Generates a Trie-like folder structure from the root path object of the OpenAPI specification.
* @param {Object} spec - specification in json format
Expand Down Expand Up @@ -585,6 +603,10 @@ module.exports = {

pathLength = currentPath.length;

if (currentPathObject.hasOwnProperty('$ref')) {
currentPathObject = this.dereferenceFromOutOfComponents(spec, currentPathObject.$ref);
}

// get method names available for this path
pathMethods = getPathMethods(Object.keys(currentPathObject));

Expand Down Expand Up @@ -799,6 +821,10 @@ module.exports = {
collectionVariables,
pathLevelServers = '';

if (currentPathObject.hasOwnProperty('$ref')) {
currentPathObject = this.dereferenceFromOutOfComponents(spec, currentPathObject.$ref);
}

// discard the leading slash, if it exists
if (path[0] === '/') {
path = path.substring(1);
Expand Down
Loading

0 comments on commit 8619eff

Please sign in to comment.