Unescape path while bundling

This commit is contained in:
Ankit Saini
2022-11-10 15:55:47 +05:30
parent f3ae564094
commit 236087cb3e
2 changed files with 17 additions and 5 deletions

View File

@@ -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

View File

@@ -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
};