From bbf0d43d42d6476a2107e7261128f604b2ba5533 Mon Sep 17 00:00:00 2001 From: Lakshya77089 Date: Tue, 16 Jun 2026 12:59:12 +0530 Subject: [PATCH] test(cross-draft): respect $schema when it follows $defs Keyword order is insignificant, so the dialect declared by $schema must apply to subschemas under $defs even when $defs appears first lexically. An implementation that builds $defs before reading $schema would use its default dialect and incorrectly treat prefixItems as an assertion here. Refs json-schema-org/JSON-Schema-Test-Suite issue on $schema ordering. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/draft2020-12/optional/cross-draft.json | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/draft2020-12/optional/cross-draft.json b/tests/draft2020-12/optional/cross-draft.json index 5113bd649..2f6d336a1 100644 --- a/tests/draft2020-12/optional/cross-draft.json +++ b/tests/draft2020-12/optional/cross-draft.json @@ -14,5 +14,32 @@ "valid": true } ] + }, + { + "description": "$schema after $defs still sets the dialect for $defs", + "comment": "keyword order is insignificant, so the dialect from $schema applies to subschemas in $defs even though $defs appears before $schema; prefixItems is not a keyword in 2019-09 and is therefore ignored", + "schema": { + "$defs": { + "list": { + "prefixItems": [{ "type": "string" }], + "minItems": 2 + } + }, + "$ref": "#/$defs/list", + "$schema": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "non-string first item is valid", + "comment": "if $defs is built with the default dialect rather than the one from $schema, prefixItems forces the first item to be a string and this fails", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "too few items is invalid", + "data": [1], + "valid": false + } + ] } ]