Hello,
In my JSON schema library a user reported a case that was not properly handled by my library. The case when $ref has a sibling $id but there is no "outer scope".
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/schema.json",
"$ref": "#/definitions/foo",
"definitions": {"foo": {"type": "object"}}
}
From what I understand from the docs, $ref should resolve against the $id because $id defines the base URI of the whole schema. Though I am not 100% sure of what should happen depending on the $ref relative URL. In my fix the above schema is now valid and the $ref resolves to http://example.com/schema.json#/definitions/foo.
I also added a test to cover what happens if there is NO base URI defined with $id. In that case, if the ref is a pointer like #/definitions/foo then everything is fine, but if the ref is something like other.json then it is a schema parse/build error, since we cannot know a base URI for other.json (whereas #/definitions/foo is fine because we can resolve against what is called :root in my lib, the root, URI-less document).
What do you think about this? What concrete tests should be added to Draft7 test suite and maybe subsequent suites?
Thank you :)
Hello,
In my JSON schema library a user reported a case that was not properly handled by my library. The case when
$refhas a sibling$idbut there is no "outer scope".{ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://example.com/schema.json", "$ref": "#/definitions/foo", "definitions": {"foo": {"type": "object"}} }From what I understand from the docs,
$refshould resolve against the$idbecause$iddefines the base URI of the whole schema. Though I am not 100% sure of what should happen depending on the$refrelative URL. In my fix the above schema is now valid and the$refresolves tohttp://example.com/schema.json#/definitions/foo.I also added a test to cover what happens if there is NO base URI defined with
$id. In that case, if the ref is a pointer like#/definitions/foothen everything is fine, but if the ref is something likeother.jsonthen it is a schema parse/build error, since we cannot know a base URI forother.json(whereas#/definitions/foois fine because we can resolve against what is called:rootin my lib, the root, URI-less document).What do you think about this? What concrete tests should be added to Draft7 test suite and maybe subsequent suites?
Thank you :)