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
@jdesrosiers

Copy link
Copy Markdown
Member

I'm not convinced that this test is necessary. If you can find an implementation that fails this test, then we should adding it, but otherwise I don't think it's needed.

(Hint: You can use the bowtie CLI to run your test against every implementation supported by bowtie.)

@jdesrosiers

Copy link
Copy Markdown
Member

I just read, #941 which this appears to be in response to. Please add Resolves #941 to the PR description.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes that the default dialect is 2020-12, but never actually states that assumption. Since this test relies on configuration (setting a default dialect), putting it in "optional" is the right choice because implementations aren't required to have a default dialect.

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.

2 participants