diff --git a/remotes/draft-next/detached-dynamicref.json b/remotes/draft-next/detached-dynamicref.json new file mode 100644 index 000000000..c1a09a583 --- /dev/null +++ b/remotes/draft-next/detached-dynamicref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft-next/detached-dynamicref.json", + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "foo": { + "$dynamicRef": "#detached" + }, + "detached": { + "$dynamicAnchor": "detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft-next/detached-ref.json b/remotes/draft-next/detached-ref.json new file mode 100644 index 000000000..d01aaa128 --- /dev/null +++ b/remotes/draft-next/detached-ref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft-next/detached-ref.json", + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "foo": { + "$ref": "#detached" + }, + "detached": { + "$anchor": "detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft2019-09/detached-ref.json b/remotes/draft2019-09/detached-ref.json new file mode 100644 index 000000000..4a3499fd1 --- /dev/null +++ b/remotes/draft2019-09/detached-ref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft2019-09/detached-ref.json", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "foo": { + "$ref": "#detached" + }, + "detached": { + "$anchor": "detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft2020-12/detached-dynamicref.json b/remotes/draft2020-12/detached-dynamicref.json new file mode 100644 index 000000000..07cce1dac --- /dev/null +++ b/remotes/draft2020-12/detached-dynamicref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft2020-12/detached-dynamicref.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "foo": { + "$dynamicRef": "#detached" + }, + "detached": { + "$dynamicAnchor": "detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft2020-12/detached-ref.json b/remotes/draft2020-12/detached-ref.json new file mode 100644 index 000000000..9c2dca93c --- /dev/null +++ b/remotes/draft2020-12/detached-ref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft2020-12/detached-ref.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "foo": { + "$ref": "#detached" + }, + "detached": { + "$anchor": "detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft6/detached-ref.json b/remotes/draft6/detached-ref.json new file mode 100644 index 000000000..05ce071ba --- /dev/null +++ b/remotes/draft6/detached-ref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft6/detached-ref.json", + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "foo": { + "$ref": "#detached" + }, + "detached": { + "$id": "#detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/remotes/draft7/detached-ref.json b/remotes/draft7/detached-ref.json new file mode 100644 index 000000000..27f2ec80a --- /dev/null +++ b/remotes/draft7/detached-ref.json @@ -0,0 +1,13 @@ +{ + "$id": "http://localhost:1234/draft7/detached-ref.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "foo": { + "$ref": "#detached" + }, + "detached": { + "$id": "#detached", + "type": "integer" + } + } +} \ No newline at end of file diff --git a/tests/draft-next/dynamicRef.json b/tests/draft-next/dynamicRef.json index a4a7c4490..428c83b34 100644 --- a/tests/draft-next/dynamicRef.json +++ b/tests/draft-next/dynamicRef.json @@ -207,45 +207,75 @@ "schema": { "$schema": "https://json-schema.org/draft/next/schema", "$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", - "$defs": { - "inner": { - "$id": "inner", - "$dynamicAnchor": "foo", - "title": "inner", - "additionalProperties": { - "$dynamicRef": "#foo" - } + "propertyDependencies": { + "kindOfList": { + "numbers": { "$ref": "numberList" }, + "strings": { "$ref": "stringList" } } }, - "if": { - "propertyNames": { - "pattern": "^[a-m]" + "$defs": { + "genericList": { + "$id": "genericList", + "properties": { + "list": { + "items": { "$dynamicRef": "#itemType" } + } + } + }, + "numberList": { + "$id": "numberList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "number" + } + }, + "$ref": "genericList" + }, + "stringList": { + "$id": "stringList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "string" + } + }, + "$ref": "genericList" } - }, - "then": { - "title": "any type of node", - "$id": "anyLeafNode", - "$dynamicAnchor": "foo", - "$ref": "inner" - }, - "else": { - "title": "integer node", - "$id": "integerNode", - "$dynamicAnchor": "foo", - "type": [ "object", "integer" ], - "$ref": "inner" } }, "tests": [ { - "description": "recurse to anyLeafNode - floats are allowed", - "data": { "alpha": 1.1 }, + "description": "number list with number values", + "data": { + "kindOfList": "numbers", + "list": [1.1] + }, "valid": true }, { - "description": "recurse to integerNode - floats are not allowed", - "data": { "november": 1.1 }, + "description": "number list with string values", + "data": { + "kindOfList": "numbers", + "list": ["foo"] + }, "valid": false + }, + { + "description": "string list with number values", + "data": { + "kindOfList": "strings", + "list": [1.1] + }, + "valid": false + }, + { + "description": "string list with string values", + "data": { + "kindOfList": "strings", + "list": ["foo"] + }, + "valid": true } ] }, @@ -564,5 +594,23 @@ "valid": false } ] + }, + { + "description": "$ref to $dynamicRef finds detached $dynamicAnchor", + "schema": { + "$ref": "http://localhost:1234/draft-next/detached-dynamicref.json#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft-next/refRemote.json b/tests/draft-next/refRemote.json index 3768b53b6..9befceb25 100644 --- a/tests/draft-next/refRemote.json +++ b/tests/draft-next/refRemote.json @@ -310,5 +310,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds detached $anchor", + "schema": { + "$ref": "http://localhost:1234/draft-next/detached-ref.json#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 79107f9e4..0bacbfc2e 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -310,5 +310,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds detached $anchor", + "schema": { + "$ref": "http://localhost:1234/draft2019-09/detached-ref.json#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json index 0f6ed4804..c1c56cb8a 100644 --- a/tests/draft2020-12/dynamicRef.json +++ b/tests/draft2020-12/dynamicRef.json @@ -392,45 +392,84 @@ "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", + "if": { + "properties": { + "kindOfList": { "const": "numbers" } + }, + "required": ["kindOfList"] + }, + "then": { "$ref": "numberList" }, + "else": { "$ref": "stringList" }, + "$defs": { - "inner": { - "$id": "inner", - "$dynamicAnchor": "foo", - "title": "inner", - "additionalProperties": { - "$dynamicRef": "#foo" + "genericList": { + "$id": "genericList", + "properties": { + "list": { + "items": { "$dynamicRef": "#itemType" } + } + }, + "$defs": { + "defaultItemType": { + "$comment": "Only needed to satisfy bookending requirement", + "$dynamicAnchor": "itemType" + } } + }, + "numberList": { + "$id": "numberList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "number" + } + }, + "$ref": "genericList" + }, + "stringList": { + "$id": "stringList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "string" + } + }, + "$ref": "genericList" } - }, - "if": { - "propertyNames": { - "pattern": "^[a-m]" - } - }, - "then": { - "title": "any type of node", - "$id": "anyLeafNode", - "$dynamicAnchor": "foo", - "$ref": "inner" - }, - "else": { - "title": "integer node", - "$id": "integerNode", - "$dynamicAnchor": "foo", - "type": [ "object", "integer" ], - "$ref": "inner" } }, "tests": [ { - "description": "recurse to anyLeafNode - floats are allowed", - "data": { "alpha": 1.1 }, + "description": "number list with number values", + "data": { + "kindOfList": "numbers", + "list": [1.1] + }, "valid": true }, { - "description": "recurse to integerNode - floats are not allowed", - "data": { "november": 1.1 }, + "description": "number list with string values", + "data": { + "kindOfList": "numbers", + "list": ["foo"] + }, + "valid": false + }, + { + "description": "string list with number values", + "data": { + "kindOfList": "strings", + "list": [1.1] + }, "valid": false + }, + { + "description": "string list with string values", + "data": { + "kindOfList": "strings", + "list": ["foo"] + }, + "valid": true } ] }, @@ -669,5 +708,23 @@ "valid": true } ] + }, + { + "description": "$ref to $dynamicRef finds detached $dynamicAnchor", + "schema": { + "$ref": "http://localhost:1234/draft2020-12/detached-dynamicref.json#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/refRemote.json b/tests/draft2020-12/refRemote.json index 2d4f99e75..ea4177f0a 100644 --- a/tests/draft2020-12/refRemote.json +++ b/tests/draft2020-12/refRemote.json @@ -310,5 +310,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds detached $anchor", + "schema": { + "$ref": "http://localhost:1234/draft2020-12/detached-ref.json#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index c2b200249..5d60fae11 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -235,5 +235,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft6/detached-ref.json#/definitions/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index c2b200249..115e12e74 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -235,5 +235,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft7/detached-ref.json#/definitions/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ]