mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Unescape path while bundling
This commit is contained in:
@@ -8,7 +8,8 @@ const _ = require('lodash'),
|
||||
jsonPointerLevelSeparator,
|
||||
isLocalRef,
|
||||
jsonPointerDecodeAndReplace,
|
||||
generateObjectName
|
||||
generateObjectName,
|
||||
unescapePath
|
||||
} = require('./jsonPointer'),
|
||||
traverseUtility = require('traverse'),
|
||||
parse = require('./parse.js'),
|
||||
@@ -311,7 +312,7 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, ve
|
||||
}
|
||||
);
|
||||
if (hasReferenceTypeKey) {
|
||||
const tempRef = calculatePath(parentFilename, property.$ref),
|
||||
const tempRef = calculatePath(parentFilename, unescapePath(property.$ref)),
|
||||
nodeTrace = handleLocalCollisions(
|
||||
getTraceFromParentKeyInComponents(this, tempRef, mainKeys, version, commonPathFromData),
|
||||
rootMainKeys
|
||||
|
||||
@@ -183,14 +183,24 @@ function removeLocalReferenceFromPath(refValue) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes local pointer inside a path
|
||||
* Unescape ~0 and ~1 character, see: https://swagger.io/docs/specification/using-ref/
|
||||
*
|
||||
* @param {string} path - value of the $ref property
|
||||
* @returns {string} - the unescaped path
|
||||
*/
|
||||
function unescapePath (path) {
|
||||
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes local pointer inside a path and unescape ~0 and ~1 character
|
||||
*
|
||||
* @param {string} refValue - value of the $ref property
|
||||
* @returns {string} - the calculated and unescaped path
|
||||
*/
|
||||
function pathSolver(refValue) {
|
||||
const path = removeLocalReferenceFromPath(refValue);
|
||||
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
return unescapePath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,5 +261,6 @@ module.exports = {
|
||||
isRemoteRef,
|
||||
localPointer,
|
||||
jsonPointerLevelSeparator,
|
||||
generateObjectName
|
||||
generateObjectName,
|
||||
unescapePath
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user