Skip to content

Clarification needed - Sibling $id and $ref in nested schema resources #787

@dylankerr-bis

Description

@dylankerr-bis

Prompted by networknt/json-schema-validator#1200 - relevant details copied below.

Suppose http://example.com/schemas/v3/bundle.json resolves to the following Compound Schema 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 resolves to http://example.com/schemas/v3/component/bar.

Based on the "$ref prevents a sibling $id from changing the base uri" test, the NetworkNT validator resolves the $ref: "./baz" in http://example.com/schemas/v3/component/bar relative to the parent schema, returning http://example.com/schemas/v3/bat instead of http://example.com/schemas/v3/component/bat which I would expect.

I notice that this test is present in older versions but has been removed in draft 2019-09 and draft 2020-12.

What is the intended behaviour, and would it be possible to get a test added to clarify this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions