From 100e9823fa0b9502fefddca89ac57663903b5115 Mon Sep 17 00:00:00 2001 From: Joel Depooter Date: Mon, 17 Mar 2025 23:21:05 -0700 Subject: [PATCH] Add tests for unevaluatedItems with minContains = 0 It is tempting to forgo evaluation of the 'contains' schema when `minContains = 0`. However, when an `unevaluatedItems` schema is present, the `contains` schema must still be evaluated as it will affect the results of the `unevaluatedItems` schema. --- tests/draft-next/unevaluatedItems.json | 31 ++++++++++++++++++++++++ tests/draft2020-12/unevaluatedItems.json | 31 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/tests/draft-next/unevaluatedItems.json b/tests/draft-next/unevaluatedItems.json index 08f6ef12..6a728f8a 100644 --- a/tests/draft-next/unevaluatedItems.json +++ b/tests/draft-next/unevaluatedItems.json @@ -711,6 +711,37 @@ } ] }, + { + "description" : "unevaluatedItems with minContains = 0", + "schema" : { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": {"type": "string"}, + "minContains": 0, + "unevaluatedItems": false + }, + "tests" : [ + { + "description": "empty array is valid", + "data": [], + "valid": true + }, + { + "description": "no items evaluated by contains", + "data": [0], + "valid": false + }, + { + "description": "some but not all items evaluated by contains", + "data": ["foo", 0], + "valid": false + }, + { + "description": "all items evaluated by contains", + "data": ["foo", "bar"], + "valid": true + } + ] + }, { "description": "non-array instances are valid", "schema": { diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index f861cefa..9614c585 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -718,6 +718,37 @@ } ] }, + { + "description" : "unevaluatedItems with minContains = 0", + "schema" : { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"type": "string"}, + "minContains": 0, + "unevaluatedItems": false + }, + "tests" : [ + { + "description": "empty array is valid", + "data": [], + "valid": true + }, + { + "description": "no items evaluated by contains", + "data": [0], + "valid": false + }, + { + "description": "some but not all items evaluated by contains", + "data": ["foo", 0], + "valid": false + }, + { + "description": "all items evaluated by contains", + "data": ["foo", "bar"], + "valid": true + } + ] + }, { "description": "non-array instances are valid", "schema": {