-
Notifications
You must be signed in to change notification settings - Fork 330
Description
There have been some issues raised here in the past in regards to Compound Schema Documents/bundles, but it looks like the support has been significantly improved since then. Although it mostly works as I would expect, I've run into an issue with how some $refs are resolved.
Suppose I call:
jsonSchemaFactory.getSchema(SchemaLocation.of(
"http://example.com/schemas/v3/bundle.json#/$defs/http:~1~1example.com~1schemas~1v3~1component~1foo"));
and http://example.com/schemas/v3/bundle.json returns the following document:
{
"$defs": {
"http://example.com/schemas/v3/component/foo": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schemas/v3/component/foo",
"type": "object",
"properties": { "bar": { "$ref": "./bar" } }
},
"http://example.com/schemas/v3/component/bar": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schemas/v3/component/bar",
"$ref": "./baz",
"unevaluatedProperties": false
},
"http://example.com/schemas/v3/component/baz": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schemas/v3/component/baz",
"type": "object",
"properties": { "bat": { "type": "string" } }
}
}
}
The $ref from http://example.com/schemas/v3/component/foo
to "./bar" is correctly resolving to http://example.com/schemas/v3/component/bar
.
The $ref from http://example.com/schemas/v3/component/bar
to "./baz" should resolve to http://example.com/schemas/v3/component/bat
but is incorrectly resolving to http://example.com/schemas/v3/bat
. I have traced this to RefValidator.resolve, which in the case of nested schema resources, resolves references relative to the parent schema, which means in this case resolving relative to http://example.com/schemas/v3/bundle.json
instead of http://example.com/schemas/v3/component/bar
.
Based on the "$ref prevents a sibling $id from changing the base uri" comment, this seems to be intentional, but it does seem to be incorrect from my reading of the spec.
Would it be possible to clarify if this is intentional behaviour, and either fix it or suggest a workaround?
Thanks for an excellent library otherwise!