Skip to content

Commit 6d2740b

Browse files
committed
Convert relative refs when resolving an external schema
Possibly corrects APIDevTools#200. This however causes tests to fail as they’re not expecting the references to be resolved. I’m not sure yet how to fix the tests. I thought I’d wait to see if the fix is valid!
1 parent 5d7f895 commit 6d2740b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/resolve-external.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function resolveExternal (parser, options) {
5252
* If any of the JSON references point to files that contain additional JSON references,
5353
* then the corresponding promise will internally reference an array of promises.
5454
*/
55-
function crawl (obj, path, $refs, options, seen) {
55+
function crawl (obj, path, $refs, options, external, seen) {
5656
seen = seen || new Set();
5757
let promises = [];
5858

@@ -62,16 +62,17 @@ function crawl (obj, path, $refs, options, seen) {
6262
promises.push(resolve$Ref(obj, path, $refs, options));
6363
}
6464
else {
65+
if (external && $Ref.is$Ref(obj)) {
66+
/* Correct the reference in the external document so we can resolve it */
67+
let withoutHash = url.stripHash(path);
68+
obj.$ref = withoutHash + obj.$ref;
69+
}
70+
6571
for (let key of Object.keys(obj)) {
6672
let keyPath = Pointer.join(path, key);
6773
let value = obj[key];
6874

69-
if ($Ref.isExternal$Ref(value)) {
70-
promises.push(resolve$Ref(value, keyPath, $refs, options));
71-
}
72-
else {
73-
promises = promises.concat(crawl(value, keyPath, $refs, options, seen));
74-
}
75+
promises = promises.concat(crawl(value, keyPath, $refs, options, external, seen));
7576
}
7677
}
7778
}
@@ -110,7 +111,7 @@ async function resolve$Ref ($ref, path, $refs, options) {
110111

111112
// Crawl the parsed value
112113
// console.log('Resolving $ref pointers in %s', withoutHash);
113-
let promises = crawl(result, withoutHash + "#", $refs, options);
114+
let promises = crawl(result, withoutHash + "#", $refs, options, true);
114115

115116
return Promise.all(promises);
116117
}

0 commit comments

Comments
 (0)