[ { "description": "Invalid use of fragments in location-independent $id", "schema": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, "tests": [ { "description": "Identifier name", "data": { "$ref": "#foo", "$defs": { "A": { "$id": "#foo", "type": "integer" } } }, "valid": false }, { "description": "Identifier name and no ref", "data": { "$defs": { "A": { "$id": "#foo" } } }, "valid": false }, { "description": "Identifier path", "data": { "$ref": "#/a/b", "$defs": { "A": { "$id": "#/a/b", "type": "integer" } } }, "valid": false }, { "description": "Identifier name with absolute URI", "data": { "$ref": "http://localhost:1234/bar#foo", "$defs": { "A": { "$id": "http://localhost:1234/bar#foo", "type": "integer" } } }, "valid": false }, { "description": "Identifier path with absolute URI", "data": { "$ref": "http://localhost:1234/bar#/a/b", "$defs": { "A": { "$id": "http://localhost:1234/bar#/a/b", "type": "integer" } } }, "valid": false }, { "description": "Identifier name with base URI change in subschema", "data": { "$id": "http://localhost:1234/root", "$ref": "http://localhost:1234/nested.json#foo", "$defs": { "A": { "$id": "nested.json", "$defs": { "B": { "$id": "#foo", "type": "integer" } } } } }, "valid": false }, { "description": "Identifier path with base URI change in subschema", "data": { "$id": "http://localhost:1234/root", "$ref": "http://localhost:1234/nested.json#/a/b", "$defs": { "A": { "$id": "nested.json", "$defs": { "B": { "$id": "#/a/b", "type": "integer" } } } } }, "valid": false } ] }, { "description": "Valid use of empty fragments in location-independent $id", "comment": "These are allowed but discouraged", "schema": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, "tests": [ { "description": "Identifier name with absolute URI", "data": { "$ref": "http://localhost:1234/bar", "$defs": { "A": { "$id": "http://localhost:1234/bar#", "type": "integer" } } }, "valid": true }, { "description": "Identifier name with base URI change in subschema", "data": { "$id": "http://localhost:1234/root", "$ref": "http://localhost:1234/nested.json#/$defs/B", "$defs": { "A": { "$id": "nested.json", "$defs": { "B": { "$id": "#", "type": "integer" } } } } }, "valid": true } ] }, { "description": "Unnormalized $ids are allowed but discouraged", "schema": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, "tests": [ { "description": "Unnormalized identifier", "data": { "$ref": "http://localhost:1234/foo/baz", "$defs": { "A": { "$id": "http://localhost:1234/foo/bar/../baz", "type": "integer" } } }, "valid": true }, { "description": "Unnormalized identifier and no ref", "data": { "$defs": { "A": { "$id": "http://localhost:1234/foo/bar/../baz", "type": "integer" } } }, "valid": true }, { "description": "Unnormalized identifier with empty fragment", "data": { "$ref": "http://localhost:1234/foo/baz", "$defs": { "A": { "$id": "http://localhost:1234/foo/bar/../baz#", "type": "integer" } } }, "valid": true }, { "description": "Unnormalized identifier with empty fragment and no ref", "data": { "$defs": { "A": { "$id": "http://localhost:1234/foo/bar/../baz#", "type": "integer" } } }, "valid": true } ] }, { "description": "$id inside an enum is not a real identifier", "comment": "the implementation must not be confused by an $id buried in the enum", "schema": { "$defs": { "id_in_enum": { "enum": [ { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" } ] }, "real_id_in_schema": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "string" }, "zzz_id_in_const": { "const": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" } } }, "anyOf": [ { "$ref": "#/$defs/id_in_enum" }, { "$ref": "https://localhost:1234/id/my_identifier.json" } ] }, "tests": [ { "description": "exact match to enum, and type matches", "data": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" }, "valid": true }, { "description": "match $ref to $id", "data": "a string to match #/$defs/id_in_enum", "valid": true }, { "description": "no match on enum or $ref to $id", "data": 1, "valid": false } ] } ]