You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to find a way for the relative link ./relativefile to load a file in the same folder... but instead it looks for mine://host/folder/relativefile
When there's a "peer" $ref though in a parent element, the relative file paths become relative to the "peer" reference. This is unexpected. I am trying to find either:
is this a bug in the code that imposes a basePath on a relative file link
or
is there a way to "break out" of a peer basePath and force a relative $ref to be applies as a file ref relative to the enclosing file?
Here's a self-contained example of the behaviour... that throws the error Error: Error resolving $ref pointer "mine://host/folder/relativefile".
'use strict';
const parser = require('json-schema-ref-parser');
const doc = {
$ref: 'mine://host/folder/path',
root: {
child: {
$ref: './relativefile'
}
}
};
const resolver = {
canRead: file => file.url.startsWith('mine://'),
read: (file) => {
if (file.url !== 'mine://host/folder/path') {
throw new Error(`Should not be asked to handle ${JSON.stringify(file)}`);
}
console.warn(`resolved ${JSON.stringify(file)}`)
return {
mine: file.url
};
}
};
const prom = parser.dereference(doc, { resolve: { mine: resolver } });
prom.then(
() => console.error('Expected an error to say ./relativefile does not exist'),
err => console.error(err.stack)
);
The full output of the above code is:
/tmp$ node bugref.js
resolved {"url":"mine://host/folder/path","extension":""}
Error: Error resolving $ref pointer "mine://host/folder/relativefile".
"mine://host/folder/relativefile" not found.
at $Refs._resolve (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/refs.js:152:11)
at dereference$Ref (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:99:23)
at crawl (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:58:26)
at crawl (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:64:28)
at dereference$Ref (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:112:24)
at crawl (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:46:22)
at dereference (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js:19:22)
at $RefParser.dereference (/tmp/node_modules/@apidevtools/json-schema-ref-parser/lib/index.js:247:5)
The text was updated successfully, but these errors were encountered:
I'm not sure this is particularly valid $ref usage anyhow. $ref and $id will be getting a bit of an overhaul for JSON Schema 2019-09 support, which is being handled by #145, so let's track all that work there.
Relative paths like
$ref: ./somefile
are expected to load the file in the same directory as the file that is being dereferenced.This behaviour is not obvious in the example:
I need to find a way for the relative link
./relativefile
to load a file in the same folder... but instead it looks formine://host/folder/relativefile
When there's a "peer" $ref though in a parent element, the relative file paths become relative to the "peer" reference. This is unexpected. I am trying to find either:
or
Here's a self-contained example of the behaviour... that throws the error
Error: Error resolving $ref pointer "mine://host/folder/relativefile".
The full output of the above code is:
The text was updated successfully, but these errors were encountered: