json-schema-org / json-schema-org/JSON-Schema-Test-Suite

Root level $ref and $id in Draft 7

Open
#894 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.