merge
This commit is contained in:
Luis Tejeda
2022-06-22 12:38:01 -05:00
12 changed files with 515 additions and 75 deletions

View File

@@ -22,17 +22,6 @@ function jsonPointerEncodeAndReplace(filePathName) {
return encodeURIComponent(filePathName.replace(tildes, escapedTildeString).replace(slashes, escapedSlashString));
}
/**
* Get a path and return a valid key name in openapi spec
* @param {string} filePathName - The filePath from the ref called
* @returns {string} A valid in openapi object name
*/
function generateObjectName(filePathName) {
let validName = filePathName.replace(/\//g, '_').replace(/#/g, '-');
validName = validName.replace(/[^a-zA-Z0-9\.\-_]/g, '');
return validName;
}
/**
* Decodes a json pointer
* replaces ~0 and ~1 for tildes and slashes
@@ -43,29 +32,41 @@ function jsonPointerDecodeAndReplace(filePathName) {
return decodeURIComponent(filePathName.replace(escapedSlash, jsonPointerLevelSeparator).replace(escapedTilde, '~'));
}
/**
* Get a path and return a valid key name in openapi spec
* @param {string} filePathName - The filePath from the ref called
* @param {string} hash - A calculated hash to join with the resultant generatedName
* @returns {string} A valid in openapi object name
*/
function generateObjectName(filePathName, hash = '') {
let decodedRef = jsonPointerDecodeAndReplace(filePathName),
validName = decodedRef.replace(/\//g, '_').replace(/#/g, '-'),
hashPart = hash ? `_${hash}` : '';
validName = `${validName.replace(/[^a-zA-Z0-9\.\-_]/g, '')}${hashPart}`;
return validName;
}
/**
* returns the key that the object in components will have could be nested
* @param {string} traceFromParent the node trace from root.
* @param {string} filePathName the filePathName of the file
* @param {string} localPath the local path that the pointer will reach
* @param {string} mainKey - The generated mainKey for the components
* @param {string} version - The current spec version
* @param {string} commonPathFromData - The common path in the file's paths
* @returns {Array} - the calculated keys in an array representing each nesting property name
*/
function getKeyInComponents(traceFromParent, filePathName, localPath, version, commonPathFromData) {
const localPart = localPath ? `${localPointer}${localPath}` : '',
{
CONTAINERS,
DEFINITIONS,
COMPONENTS_KEYS,
INLINE,
ROOT_CONTAINERS_KEYS
} = getBundleRulesDataByVersion(version);
function getKeyInComponents(traceFromParent, mainKey, version, commonPathFromData) {
const {
CONTAINERS,
DEFINITIONS,
COMPONENTS_KEYS,
INLINE,
ROOT_CONTAINERS_KEYS
} = getBundleRulesDataByVersion(version);
let result,
newFPN = filePathName.replace(commonPathFromData, ''),
newFPN = mainKey.replace(generateObjectName(commonPathFromData), ''),
trace = [
...traceFromParent,
jsonPointerDecodeAndReplace(`${newFPN}${localPart}`)
jsonPointerDecodeAndReplace(newFPN)
].reverse(),
traceToKey = [],
matchFound = false,
@@ -93,7 +94,7 @@ function getKeyInComponents(traceFromParent, filePathName, localPath, version, c
result = matchFound ?
traceToKey.reverse() :
[];
return result.map(generateObjectName);
return result;
}
/**