Skip to content

test(cross-draft): respect $schema when it follows $defs#944

Open
Lakshya77089 wants to merge 1 commit into
json-schema-org:mainfrom
Lakshya77089:test/schema-dialect-keyword-order
Open

test(cross-draft): respect $schema when it follows $defs#944
Lakshya77089 wants to merge 1 commit into
json-schema-org:mainfrom
Lakshya77089:test/schema-dialect-keyword-order

Conversation

@Lakshya77089

Copy link
Copy Markdown

Adds a test asserting that the dialect declared by $schema is applied to subschemas under $defs even when $defs appears before $schema lexically. This covers the "keyword ordering MUST be insignificant" banner raised in the linked issue.

The reported bug: an implementation that builds the $defs subschemas before reading $schema ends up using its default dialect rather than the one the schema declares.

How the test detects it

{
    "$defs": { "list": { "prefixItems": [{ "type": "string" }], "minItems": 2 } },
    "$ref": "#/$defs/list",
    "$schema": "https://json-schema.org/draft/2019-09/schema"
}

prefixItems is not a keyword in 2019-09, so [1, 2, 3] is valid only if the implementation read $schema (and selected the 2019-09 dialect) before building $defs. An implementation that defaulted the dialect would treat prefixItems as an assertion and reject the array — failing the valid: true test. minItems (recognized in both dialects) gives a stable invalid case as well.

The case lives in optional/cross-draft.json because detecting the bug inherently requires a root $schema that differs from the folder's default dialect, which is the same situation the existing cross-draft cases exercise. tests/latest is a symlink to draft2020-12, so it is covered automatically.

Verified locally: structurally valid against test-schema.json, valid under the 2020-12 metaschema (check_schema), and a $schema-respecting reference implementation returns the expected true/false.

Note for reviewers

I added this only in the 2020-12 → 2019-09 direction. The mirror (an older-draft folder declaring a newer inner $schema) trips the suite's test_arbitrary_schemas_do_not_use_unknown_keywords guard when the newer keyword appears inline, and the clean older-dialect discriminators tangle with $ref-sibling semantics. Happy to add the other direction via remotes if that's preferred.

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
@Lakshya77089 Lakshya77089 requested a review from a team as a code owner June 16, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant