json-schema-org / json-schema-org/JSON-Schema-Test-Suite
Root level $ref and $id in Draft 7
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 750
- Forks
- 307
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 24
Description
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 :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Draft 7 test suite and the root-level schema example in the issue. Review existing tests for $ref, $id, URI resolution, and later specification suites, then determine the concrete cases needed for sibling $id values with and without a base URI. Done means the agreed behavior is represented by language-agnostic tests, including pointer and relative-reference cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100