From c9a788c856b28835ebf65d94cc995fc78fea17f0 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Thu, 4 Jun 2020 13:30:30 -0700 Subject: [PATCH 1/7] test $recursiveRef + $recursiveAnchor --- tests/draft2019-09/recursiveRef.json | 134 +++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tests/draft2019-09/recursiveRef.json diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json new file mode 100644 index 00000000..9b4987f9 --- /dev/null +++ b/tests/draft2019-09/recursiveRef.json @@ -0,0 +1,134 @@ +[ + { + "description": "$recursiveRef without $recursiveAnchor works like $ref", + "schema": { + "properties": { + "foo": { "$recursiveRef": "#" } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": { "foo": { "foo": false } }, + "valid": true + }, + { + "description": "mismatch", + "data": { "bar": false }, + "valid": false + }, + { + "description": "recursive mismatch", + "data": { "foo": { "bar": false } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef without using nesting", + "schema": { + "$id": "http://localhost:4242", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, no match", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with nesting", + "schema": { + "$id": "http://localhost:4242", + "$recursiveAnchor": true, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer now matches as a property value", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, properties match with $recursiveRef", + "data": { "foo": { "bar": 1 } }, + "valid": true + } + ] + } +] From 18bac7acf16a49e764dd0ee600316206877a3bf4 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Tue, 23 Jun 2020 11:12:36 -0700 Subject: [PATCH 2/7] squash: use a unique $id to prevent namespace collisions across tests --- tests/draft2019-09/recursiveRef.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index 9b4987f9..7c049911 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -33,7 +33,7 @@ { "description": "$recursiveRef without using nesting", "schema": { - "$id": "http://localhost:4242", + "$id": "http://localhost:4242/recursiveRef2/schema.json", "$defs": { "myobject": { "$id": "myobject.json", @@ -83,7 +83,7 @@ { "description": "$recursiveRef with nesting", "schema": { - "$id": "http://localhost:4242", + "$id": "http://localhost:4242/recursiveRef3/schema.json", "$recursiveAnchor": true, "$defs": { "myobject": { From 33dca8743bff624c2933f0567dc2ab7cb84dfcf7 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sat, 4 Jul 2020 15:57:41 -0700 Subject: [PATCH 3/7] squash: test $recursiveRef when $recursiveAnchor is false --- tests/draft2019-09/recursiveRef.json | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index 7c049911..6bd50671 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -130,5 +130,56 @@ "valid": true } ] + }, + { + "description": "$recursiveRef with $recursiveAnchor: false works like $ref", + "schema": { + "$id": "http://localhost:4242/recursiveRef4/schema.json", + "$recursiveAnchor": false, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, integer does not match as a property value", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] } ] From 13e3f91aaae79f2fdd0398c669783f24b0a7a438 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sat, 4 Jul 2020 16:14:59 -0700 Subject: [PATCH 4/7] squash: test $recursiveRef when $recursiveAnchor is absent --- tests/draft2019-09/recursiveRef.json | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index 6bd50671..6a9e793b 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -181,5 +181,55 @@ "valid": false } ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor works like $ref", + "schema": { + "$id": "http://localhost:4242/recursiveRef4/schema.json", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, integer does not match as a property value", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] } ] From 2b4df7bc754a4bc9fc89a189ce8cada414fe9117 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sat, 4 Jul 2020 17:08:10 -0700 Subject: [PATCH 5/7] squash: fix duplicate $id --- tests/draft2019-09/recursiveRef.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index 6a9e793b..da4d87a1 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -185,7 +185,7 @@ { "description": "$recursiveRef with no $recursiveAnchor works like $ref", "schema": { - "$id": "http://localhost:4242/recursiveRef4/schema.json", + "$id": "http://localhost:4242/recursiveRef5/schema.json", "$defs": { "myobject": { "$id": "myobject.json", From 18a5ffb07e74946d8c689e094fb5ce55ab1b2db1 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sat, 4 Jul 2020 17:09:00 -0700 Subject: [PATCH 6/7] squash: test $recursive$ref with no $recursiveAnchor in the initial target schema resource see https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8.2.4.2 --- tests/draft2019-09/recursiveRef.json | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index da4d87a1..749b1cd0 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -231,5 +231,43 @@ "valid": false } ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the initial target schema resource", + "schema": { + "$id": "http://localhost:4242/recursiveRef6/base.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "boolean" }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/recursiveRef6/inner.json", + "$comment": "there is no $recursiveAnchor: true here, so we do NOT recurse to the base", + "anyOf": [ + { "type": "integer" }, + { "type": "object", "additionalProperties": { "$recursiveRef": "#" } } + ] + } + } + ] + }, + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { "foo": true }, + "valid": false + }, + { + "description": "leaf node matches: recursion only uses inner schema", + "data": { "foo": { "bar": 1 } }, + "valid": true + }, + { + "description": "leaf node does not match: recursion only uses inner schema", + "data": { "foo": { "bar": true } }, + "valid": false + } + ] } ] From 7492ff6fcada2b22242915ac38cef2a60f582f98 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Tue, 17 Nov 2020 16:26:25 -0800 Subject: [PATCH 7/7] squash: one more test, with no recursiveAnchor in the outer resource (again reverts to normal $ref behaviour) --- tests/draft2019-09/recursiveRef.json | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json index 749b1cd0..9a1d6a8d 100644 --- a/tests/draft2019-09/recursiveRef.json +++ b/tests/draft2019-09/recursiveRef.json @@ -258,6 +258,43 @@ "data": { "foo": true }, "valid": false }, + { + "description": "leaf node matches: recursion uses the inner schema", + "data": { "foo": { "bar": 1 } }, + "valid": true + }, + { + "description": "leaf node matches: recursion uses the inner schema", + "data": { "foo": { "bar": true } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the outer schema resource", + "schema": { + "$id": "http://localhost:4242/recursiveRef7/base.json", + "anyOf": [ + { "type": "boolean" }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/recursiveRef7/inner.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "integer" }, + { "type": "object", "additionalProperties": { "$recursiveRef": "#" } } + ] + } + } + ] + }, + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { "foo": true }, + "valid": false + }, { "description": "leaf node matches: recursion only uses inner schema", "data": { "foo": { "bar": 1 } },