-
-
Notifications
You must be signed in to change notification settings - Fork 239
Description
It seems that when bundling a schema $id
attributes aren't considered which makes the output incompatible with other JSON Schema tools, for example:
a.json
:
{
"$id": "https://schema.example.com/a.json",
"b": {
"$ref": "b.json"
}
}
b.json
:
{
"$id": "https://schema.example.com/b.json",
"properties": {
"bar": {
"$ref": "#/definitions/thing"
}
},
"definitions": {
"thing": {
"type": "string"
}
}
}
Some code:
const RefParse = require('json-schema-ref-parser');
RefParse.bundle('a.json')
.then(s => {
console.log(JSON.stringify(s, null, 2));
});
Outputs:
{
"$id": "https://schema.example.com/a.json",
"b": {
"$id": "https://schema.example.com/b.json",
"properties": {
"bar": {
"$ref": "#/b/definitions/thing"
}
},
"definitions": {
"thing": {
"type": "string"
}
}
}
}
The issue is that in JSON Schema b.properties.bar.$ref
is resolved against the nested b.$id
giving https://schema.example.com/b.json#/b/definitions/bar
which doesn't actually exist.
This breaks other tools, like trying to use the bundled schema in Ajv.
I saw the comment on #22 that the aims of this library do not include supporting JSON Schema and the $id
keyword, but it's confusing as the first line of the README says: "Parse, Resolve, and Dereference JSON Schema $ref pointers" 😄 Latest JSON Schema has it's own definition of $ref
and no longer uses the expired JSON Reference spec 😮
Any chance of an option to consider $id
when bundling?