References to references resolve relative to self, not baseUrl
See original GitHub issueIssue Description
Given the schema, mySchema.json
:
{ "properties": { "thing": { "$ref": "./schemas/thing.json" } } }
Where thing.json
is:
{ "properties": { "inner_thing": { "$ref": "./schemas/inner_thing.json" } } }
Attempting to deference mySchema.json
at baseUrl json/
, results in the dereference function observing the baseUrl for mySchema.json
, but not for thing.json
, leading to trying to read the file inner_thing.json
at: json/schemas/json/schemas/inner_thing.json
.
As such, there is no way to resolve schema structure whereby there are schemas that reference either of thing.json
or inner_thing.json
. Could a resolver option be included that says “always resolve relative to the supplied cwd”?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Just noticed this as well:
Folder structure
{rootDir}
node_modules
package.json
schemas
base.json
child.json
grandchild.json
Schemas
Expected behavior is that calling
$RefParser.dereference()
withbase.json
resolves both$ref
s to filepaths{rootDir}/schemas/{child|grandchild}.json
and returns:Actual behavior: calling
$RefParser.dereference
correctly resolves{rootDir}/schemas/child.json
, but then attempts to resolve filepath{rootDir}/schemas/schemas/grandchild.json
, which throws an error:Also, it would be great if the eventual fix would add a parameter to the resolve options, as this library is used in a lot of other JSON Schema and OpenAPI libraries and they usually expose the options object of this library.
Currently I have to create a complete dereferenced JSONSchema using the above logic and use that schema file for the rest of my API generation and validation toolchain as there is no way to declare what kind of $ref logic is desired via the options object.