From 2834c6306c3c72983ab2a6572d3dc7f3bb4d4c83 Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Tue, 24 Oct 2023 11:59:21 -0700 Subject: [PATCH 1/4] Add tests for unevaluated with dynamic reference --- tests/draft2019-09/unevaluatedItems.json | 44 ++++++++++++++ tests/draft2019-09/unevaluatedProperties.json | 57 +++++++++++++++++++ tests/draft2020-12/unevaluatedItems.json | 48 ++++++++++++++++ tests/draft2020-12/unevaluatedProperties.json | 54 ++++++++++++++++++ 4 files changed, 203 insertions(+) diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json index 53565a0b..8750db29 100644 --- a/tests/draft2019-09/unevaluatedItems.json +++ b/tests/draft2019-09/unevaluatedItems.json @@ -480,6 +480,50 @@ } ] }, + { + "description": "unevaluatedItems with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/extended-tree", + + "$recursiveAnchor": true, + + "$ref": "/tree", + "items": [ + true, + true, + { "type": "string" } + ], + + "$defs": { + "tree": { + "$id": "/tree", + "$recursiveAnchor": true, + + "type": "array", + "items": [ + { "type": "number" }, + { + "$recursiveRef": "#", + "unevaluatedItems": false + } + ] + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [1, [2, [], "b"], "a"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": [1, [2, [], "b", "too many"], "a"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json index a6cce8bb..01acc215 100644 --- a/tests/draft2019-09/unevaluatedProperties.json +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -715,6 +715,63 @@ } ] }, + { + "description": "unevaluatedProperties with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/extended-tree", + + "$recursiveAnchor": true, + + "$ref": "/tree", + "properties": { + "name": { "type": "string" } + }, + + "$defs": { + "tree": { + "$id": "/tree", + "$recursiveAnchor": true, + + "type": "object", + "properties": { + "node": true, + "branches": { + "$recursiveRef": "#", + "unevaluatedProperties": false + } + }, + "required": ["node"] + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "name": "b", + "node": 2 + } + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "foo": "b", + "node": 2 + } + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 2615c4c4..fa8e2e88 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -461,6 +461,54 @@ } ] }, + { + "description": "unevaluatedItems with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/derived", + + "$ref": "/baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "prefixItems": [ + true, + { "type": "string" } + ] + }, + "baseSchema": { + "$id": "/baseSchema", + + "type": "array", + "prefixItems": [ + { "type": "string" } + ], + "$dynamicRef": "#addons", + "unevaluatedItems": false, + + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json index f7fb420f..84bdd716 100644 --- a/tests/draft2020-12/unevaluatedProperties.json +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -715,6 +715,60 @@ } ] }, + { + "description": "unevaluatedProperties with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/derived", + + "$ref": "/baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "properties": { + "bar": { "type": "string" } + } + }, + "baseSchema": { + "$id": "/baseSchema", + + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "$dynamicRef": "#addons", + "unevaluatedProperties": false, + + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { From 8ba1c90dc62b9ddd6c2efc2c395d122a8d68135d Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Fri, 27 Oct 2023 12:25:17 -0700 Subject: [PATCH 2/4] Update unevaluted with dynamic ref to be more likely to catch errors --- tests/draft2019-09/unevaluatedItems.json | 5 +++-- tests/draft2019-09/unevaluatedProperties.json | 5 +++-- tests/draft2020-12/unevaluatedItems.json | 3 ++- tests/draft2020-12/unevaluatedProperties.json | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json index 8750db29..9c115ab3 100644 --- a/tests/draft2019-09/unevaluatedItems.json +++ b/tests/draft2019-09/unevaluatedItems.json @@ -504,8 +504,9 @@ "items": [ { "type": "number" }, { - "$recursiveRef": "#", - "unevaluatedItems": false + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "$recursiveRef": "#" } ] } diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json index 01acc215..4e0d3ec8 100644 --- a/tests/draft2019-09/unevaluatedProperties.json +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -737,8 +737,9 @@ "properties": { "node": true, "branches": { - "$recursiveRef": "#", - "unevaluatedProperties": false + "$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "$recursiveRef": "#" } }, "required": ["node"] diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index fa8e2e88..ddc35da2 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -480,12 +480,13 @@ "baseSchema": { "$id": "/baseSchema", + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, "type": "array", "prefixItems": [ { "type": "string" } ], "$dynamicRef": "#addons", - "unevaluatedItems": false, "$defs": { "defaultAddons": { diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json index 84bdd716..023e84a5 100644 --- a/tests/draft2020-12/unevaluatedProperties.json +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -733,12 +733,13 @@ "baseSchema": { "$id": "/baseSchema", + "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, "type": "object", "properties": { "foo": { "type": "string" } }, "$dynamicRef": "#addons", - "unevaluatedProperties": false, "$defs": { "defaultAddons": { From 492220466f4133b45b57654ae70eaba2b83f8211 Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Fri, 27 Oct 2023 12:25:57 -0700 Subject: [PATCH 3/4] Add unevaluted with dynamic ref tests to draft-next --- tests/draft-next/unevaluatedItems.json | 42 +++++++++++++++++++++ tests/draft-next/unevaluatedProperties.json | 28 ++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/tests/draft-next/unevaluatedItems.json b/tests/draft-next/unevaluatedItems.json index 7379afb4..8dda001f 100644 --- a/tests/draft-next/unevaluatedItems.json +++ b/tests/draft-next/unevaluatedItems.json @@ -461,6 +461,48 @@ } ] }, + { + "description": "unevaluatedItems with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://example.com/derived", + + "$ref": "/baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "prefixItems": [ + true, + { "type": "string" } + ] + }, + "baseSchema": { + "$id": "/baseSchema", + + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "type": "array", + "prefixItems": [ + { "type": "string" } + ], + "$dynamicRef": "#addons" + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json index 69fe8a00..e763fc10 100644 --- a/tests/draft-next/unevaluatedProperties.json +++ b/tests/draft-next/unevaluatedProperties.json @@ -715,6 +715,34 @@ } ] }, + { + "description": "unevaluatedProperties with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://example.com/derived", + + "$ref": "/baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "properties": { + "bar": { "type": "string" } + } + }, + "baseSchema": { + "$id": "/baseSchema", + + "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "$dynamicRef": "#addons" + } + } + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { From 5d0c05fa60652e91ce5f95859c7b4751668a4e8a Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Wed, 15 Nov 2023 16:20:40 -0800 Subject: [PATCH 4/4] Fix copy/paste error --- tests/draft-next/unevaluatedProperties.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json index e763fc10..4fe7986d 100644 --- a/tests/draft-next/unevaluatedProperties.json +++ b/tests/draft-next/unevaluatedProperties.json @@ -743,6 +743,26 @@ } } }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": {