Skip to content

Commit db568e2

Browse files
committed
Add id and fix title for recursive merge.
1 parent 8af5802 commit db568e2

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/dereference.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,34 @@ function crawl(obj, globallyUniqueFqdnPath, pathFromTopOfDocument, alreadyResolv
8282
return { value: null };
8383
}
8484

85+
// Dereference the JSON reference
86+
const dereferencedValue = $Ref.dereference(obj, pointer.value);
87+
8588
// Merge the title into the object, we need to update the object, so that the update propagates forward and also ends up in the cache
86-
obj.title = obj.title || obj.$ref.split('/').slice(-1)[0];
89+
obj.title = obj.title || dereferencedValue.title || obj.$ref.split('/').slice(-1)[0];
8790

88-
// Dereference the JSON reference
89-
const dereferencedValue = mergeRefObject(obj, $Ref.dereference(obj, pointer.value));
91+
const mergedDereferencedValue = mergeRefObject(obj, dereferencedValue);
9092

9193
if (pointer.circular) {
9294
// The pointer is a DIRECT circular reference (i.e. it references itself).
9395
// So replace the $ref path with the absolute path from the JSON Schema root
94-
dereferencedValue.$ref = pathFromTopOfDocument;
96+
mergedDereferencedValue.$ref = pathFromTopOfDocument;
9597

9698
foundCircularReference(globallyUniqueFqdnPath, $refs, options);
97-
return { value: dereferencedValue, circular: true };
99+
return { value: mergedDereferencedValue, circular: true };
98100
}
99101

100102
if (options.dereference.onDereference) {
101-
options.dereference.onDereference(pathFromTopOfDocument, dereferencedValue);
103+
options.dereference.onDereference(pathFromTopOfDocument, mergedDereferencedValue);
102104
}
103105

104-
const result = crawl(dereferencedValue, pointer.path, pathFromTopOfDocument, new Set(alreadyResolvedObjects).add(obj), $refs, options);
106+
const result = crawl(mergedDereferencedValue, pointer.path, pathFromTopOfDocument, new Set(alreadyResolvedObjects).add(obj), $refs, options);
105107
if (result.circular && options && options.dereference && options.dereference.circular && options.dereference.circular === 'ignore') {
106108
return {
107109
circular: false,
108110
value: {
109111
...obj,
110-
circularReference: { $ref: obj.$ref, name: obj.$ref.split('/').slice(-1)[0] },
112+
circularReference: { $ref: obj.$ref, name: obj.$ref.split('/').slice(-1)[0], id: obj.$ref.split('/').slice(-1)[0] },
111113
},
112114
};
113115
}

0 commit comments

Comments
 (0)