Fix value resolution.

- When value is not below the properties key, it will be resolved inline
- Avoiding to overwrite the already created references when they are called again from a different node
This commit is contained in:
Erik Mendoza
2022-07-06 15:24:29 -05:00
parent b402ab2eac
commit 4bf664e80a
8 changed files with 97 additions and 72 deletions

View File

@@ -288,10 +288,11 @@ function handleLocalCollisions(trace, initialMainKeys) {
* @param {object} rootMainKeys - A dictionary with the component keys in local components object and its mainKeys
* @param {string} commonPathFromData - The common path in the file's paths
* @param {Array} allData - array of { path, content} objects
* @param {object} globalReferences - The accumulated global references from all nodes
* @returns {object} - The references in current node and the new content from the node
*/
function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, version, rootMainKeys,
commonPathFromData, allData) {
commonPathFromData, allData, globalReferences) {
let referencesInNode = [],
nodeReferenceDirectory = {},
mainKeys = {};
@@ -349,17 +350,19 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, ve
inline = true;
}
nodeReferenceDirectory[tempRef] = {
local,
keyInComponents: nodeTrace,
node: newValue,
reference: inline ? newRefInDoc : referenceInDocument,
traceToParent,
parentNodeKey: parentFilename,
mainKeyInTrace: nodeTrace[nodeTrace.length - 1],
refHasContent,
inline
};
if (_.isNil(globalReferences[tempRef])) {
nodeReferenceDirectory[tempRef] = {
local,
keyInComponents: nodeTrace,
node: newValue,
reference: inline ? newRefInDoc : referenceInDocument,
traceToParent,
parentNodeKey: parentFilename,
mainKeyInTrace: nodeTrace[nodeTrace.length - 1],
refHasContent,
inline
};
}
mainKeys[componentKey] = tempRef;
@@ -381,9 +384,11 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, ve
* @param {string} version - The current version
* @param {object} rootMainKeys - A dictionary with the component keys in local components object and its mainKeys
* @param {string} commonPathFromData - The common path in the file's paths
* @param {object} globalReferences - The accumulated global refernces from all nodes
* @returns {object} - Detect root files result object
*/
function getNodeContentAndReferences (currentNode, allData, specRoot, version, rootMainKeys, commonPathFromData) {
function getNodeContentAndReferences (currentNode, allData, specRoot, version, rootMainKeys,
commonPathFromData, globalReferences) {
let graphAdj = [],
missingNodes = [],
nodeContent,
@@ -408,7 +413,8 @@ function getNodeContentAndReferences (currentNode, allData, specRoot, version, r
version,
rootMainKeys,
commonPathFromData,
allData
allData,
globalReferences
);
referencesInNode.forEach((reference) => {
@@ -640,8 +646,16 @@ module.exports = {
commonPathFromData = Utils.findCommonSubpath(allData.map((fileData) => {
return fileData.fileName;
}));
rootContextData = algorithm.traverseAndBundle(specRoot, (currentNode) => {
return getNodeContentAndReferences(currentNode, allData, specRoot, version, initialMainKeys, commonPathFromData);
rootContextData = algorithm.traverseAndBundle(specRoot, (currentNode, globalReferences) => {
return getNodeContentAndReferences(
currentNode,
allData,
specRoot,
version,
initialMainKeys,
commonPathFromData,
globalReferences
);
});
components = generateComponentsWrapper(
specRoot.parsed.oasObject,