Skip to content

Question about $id #349

Closed
Closed
@vivin

Description

@vivin

Perhaps this has been covered elsewhere, but I couldn't find it. I found the definition for $id at http://json-schema.org/latest/json-schema-core.html#rfc.section.9.2 a bit confusing; specifically this part:

To name subschemas in a JSON Schema document, subschemas can use "$id" to give themselves a document-local identifier. This is done by setting "$id" to a URI reference consisting only of a fragment. The fragment identifier MUST begin with a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").

The effect of defining an "$id" that neither matches the above requirements nor is a valid JSON pointer is not defined.

The example that is provided is:

{
    "$id": "http://example.com/root.json",
    "definitions": {
        "A": { "$id": "#foo" },
        "B": {
            "$id": "other.json",
            "definitions": {
                "X": { "$id": "#bar" },
                "Y": { "$id": "t/inner.json" }
            }
        },
        "C": {
            "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
        }
    }
}

The specification says that $id is a URI reference consisting only of a fragment, which I assume is anything starting with a #. It then goes on to say that the effect of defining an $id that doesn't match the above requirements, or is not a valid JSON pointer, is not defined.

Doesn't that mean that other.json and t/inner.json don't meet this criteria? Neither of those are fragments. Also, what does it mean when the fragment can be a JSON pointer? Can you have an id like #foo/bar/baz?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions