From f400802c35aa02ea32d2936dda962b3dab2afc45 Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Sat, 10 Apr 2021 08:05:41 +0200 Subject: [PATCH 1/5] Add tests for unevaluatedItems interaction with contains ref json-schema-org/JSON-Schema-Test-Suite#293 --- tests/draft2020-12/unevaluatedItems.json | 117 +++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 13c80a2a..c21600d5 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -485,5 +485,122 @@ "valid": false } ] + }, + { + "description": "unevaluatedItems depends on adjacent contains", + "schema": { + "prefixItems": [true], + "contains": {"type": "string"}, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "second item is evaluated by contains", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "contains fails, second item is not evaluated", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "contains passes, second item is not evaluated", + "data": [ 1, 2, "foo" ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on nested contains", + "schema": { + "anyOf": [ + { + "prefixItems": [{"type": "integer"}] + }, + { + "contains": {"type": "string"} + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "single integer is evaluated by prefixItems", + "data": [ 1 ], + "valid": true + }, + { + "description": "single string is evaluated by contains", + "data": [ "foo" ], + "valid": true + }, + { + "description": "second item is evaluated by contains", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "second item is not evaluated, contains fails", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "second item is not evaluated, contains passes", + "data": [ 1, 2, "foo" ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on multiple nested contains", + "schema": { + "allOf": [ + { + "prefixItems": [true] + }, + { + "contains": {"multipleOf": 2} + } + ], + "anyOf": [ + { + "prefixItems": [true] + }, + { + "contains": {"multipleOf": 3} + } + ], + "unevaluatedItems": { + "multipleOf": 5 + } + }, + "tests": [ + { + "description": "second item is evaluated by contains #1", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "third item is evaluated by contains #2", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "items 3, 4 are evaluated by contains #2, #1", + "data": [ 1, 2, 3, 4 ], + "valid": true + }, + { + "description": "item 5 not evaluated, passes unevaluatedItems", + "data": [ 1, 2, 3, 4, 5, 6 ], + "valid": true + }, + { + "description": "item 5 not evaluated, fails unevaluatedItems", + "data": [ 1, 2, 3, 4, 7, 8 ], + "valid": false + } + ] } ] From 84e1d5a9822cfb5cf2cfa81d8dcda62542d04cad Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:24:03 +0200 Subject: [PATCH 2/5] Add another test case for unevaluatedItems-contains interaction We use contains and unevaluatedItems to define a dependency relationship over the array items. The array may contain any sequence of a's, b's and c's, but b's may only be present if there is at least one a, and c's may only be present if there is at least one b. --- tests/draft2020-12/unevaluatedItems.json | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index c21600d5..94b81e56 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -602,5 +602,66 @@ "valid": false } ] + }, + { + "description": "unevaluatedItems and contains interact to control item dependency relationship", + "schema": { + "if": { + "contains": {"const": "a"} + }, + "then": { + "if": { + "contains": {"const": "b"} + }, + "then": { + "if": { + "contains": {"const": "c"} + } + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "empty array is valid", + "data": [], + "valid": true + }, + { + "description": "only a's are valid", + "data": [ "a", "a" ], + "valid": true + }, + { + "description": "a's and b's are valid", + "data": [ "a", "b", "a", "b", "a" ], + "valid": true + }, + { + "description": "a's, b's and c's are valid", + "data": [ "c", "a", "c", "c", "b", "a" ], + "valid": true + }, + { + "description": "only b's are invalid", + "data": [ "b", "b" ], + "valid": false + }, + { + "description": "only c's are invalid", + "data": [ "c", "c" ], + "valid": false + }, + { + "description": "only b's and c's are invalid", + "data": [ "c", "b", "c", "b", "c" ], + "valid": false + }, + { + "description": "only a's and c's are invalid", + "data": [ "c", "a", "c", "a", "c" ], + "valid": false + } + ] } ] From d3b88001a523a3da394cb53a99936189b9325070 Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Mon, 12 Apr 2021 08:53:47 +0200 Subject: [PATCH 3/5] Update tests/draft2020-12/unevaluatedItems.json Co-authored-by: Jason Desrosiers --- tests/draft2020-12/unevaluatedItems.json | 41 ------------------------ 1 file changed, 41 deletions(-) diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 94b81e56..0b9ea265 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -511,47 +511,6 @@ } ] }, - { - "description": "unevaluatedItems depends on nested contains", - "schema": { - "anyOf": [ - { - "prefixItems": [{"type": "integer"}] - }, - { - "contains": {"type": "string"} - } - ], - "unevaluatedItems": false - }, - "tests": [ - { - "description": "single integer is evaluated by prefixItems", - "data": [ 1 ], - "valid": true - }, - { - "description": "single string is evaluated by contains", - "data": [ "foo" ], - "valid": true - }, - { - "description": "second item is evaluated by contains", - "data": [ 1, "foo" ], - "valid": true - }, - { - "description": "second item is not evaluated, contains fails", - "data": [ 1, 2 ], - "valid": false - }, - { - "description": "second item is not evaluated, contains passes", - "data": [ 1, 2, "foo" ], - "valid": false - } - ] - }, { "description": "unevaluatedItems depends on multiple nested contains", "schema": { From 3390c871b44e1fdd694bb5dff0911ab6c80ade9f Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Tue, 13 Apr 2021 09:53:56 +0200 Subject: [PATCH 4/5] Update tests/draft2020-12/unevaluatedItems.json Co-authored-by: Jason Desrosiers --- tests/draft2020-12/unevaluatedItems.json | 43 ++++-------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 0b9ea265..94e13b9d 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -515,49 +515,20 @@ "description": "unevaluatedItems depends on multiple nested contains", "schema": { "allOf": [ - { - "prefixItems": [true] - }, - { - "contains": {"multipleOf": 2} - } + { "contains": { "multipleOf": 2 } } + { "contains": { "multipleOf": 3 } } ], - "anyOf": [ - { - "prefixItems": [true] - }, - { - "contains": {"multipleOf": 3} - } - ], - "unevaluatedItems": { - "multipleOf": 5 - } + "unevaluatedItems": { "multipleOf": 5 } }, "tests": [ { - "description": "second item is evaluated by contains #1", - "data": [ 1, 2 ], - "valid": true - }, - { - "description": "third item is evaluated by contains #2", - "data": [ 1, 2, 3 ], - "valid": true - }, - { - "description": "items 3, 4 are evaluated by contains #2, #1", - "data": [ 1, 2, 3, 4 ], - "valid": true - }, - { - "description": "item 5 not evaluated, passes unevaluatedItems", - "data": [ 1, 2, 3, 4, 5, 6 ], + "description": "5 not evaluated, passes unevaluatedItems", + "data": [ 2, 3, 4, 5, 6 ], "valid": true }, { - "description": "item 5 not evaluated, fails unevaluatedItems", - "data": [ 1, 2, 3, 4, 7, 8 ], + "description": "7 not evaluated, fails unevaluatedItems", + "data": [ 2, 3, 4, 7, 8 ], "valid": false } ] From 7cf78800c3e3338568b9ec5586da6871f44fa931 Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Tue, 13 Apr 2021 09:56:53 +0200 Subject: [PATCH 5/5] Add missing comma --- tests/draft2020-12/unevaluatedItems.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 94e13b9d..00617695 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -515,7 +515,7 @@ "description": "unevaluatedItems depends on multiple nested contains", "schema": { "allOf": [ - { "contains": { "multipleOf": 2 } } + { "contains": { "multipleOf": 2 } }, { "contains": { "multipleOf": 3 } } ], "unevaluatedItems": { "multipleOf": 5 }