Skip to content

Add a test for 2019's interaction between additional/unevaluatedItems #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

Julian
Copy link
Member

@Julian Julian commented Feb 21, 2023

The interesting bit here actually only applies to 2019, as it's the only draft containing both unevaluatedItems as well as additionalItems -- the latter in its specified behavior containing:

if "items" is absent or its annotation result is the
boolean true, "additionalItems" MUST be ignored.

(from https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02#section-9.3.1.2)

In newer drafts (i.e. 2020), when additionalItems "became" items, this condition was dropped (i.e. items without a neighboring prefixItems now is indeed not ignored).

Refs: https://github.com/orgs/json-schema-org/discussions/57

Closes: #292

@Julian Julian requested a review from a team as a code owner February 21, 2023 14:58
@Julian
Copy link
Member Author

Julian commented Feb 21, 2023

This Slack thread (re-)raised the missing test added here.

As mentioned in the thread, around half of all implementations supported by Bowtie get this wrong:

⊙  2>/dev/null bowtie validate -D 2019 $(find ~/Development/bowtie/implementations/ -mindepth 1 -maxdepth 1 -type d | sed 's/.*\/implementations\//-i /') <(printf '{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "additionalItems": {"type": "number"},
  "unevaluatedItems": {"type": "string"}
}
') <(printf '["foo", 1]') | rg implementation | jq '{implementation: .implementation, valid: .results[0].valid}'
{
  "implementation": "ghcr.io/bowtie-json-schema/ts-vscode-json-languageservice",
  "valid": false
}
{
  "implementation": "ghcr.io/bowtie-json-schema/python-jsonschema",
  "valid": true
}
{
  "implementation": "ghcr.io/bowtie-json-schema/go-jsonschema",
  "valid": false
}
{
  "implementation": "ghcr.io/bowtie-json-schema/python-jschon",
  "valid": false
}
{
  "implementation": "ghcr.io/bowtie-json-schema/dotnet-jsonschema-net",
  "valid": false
}
{
  "implementation": "ghcr.io/bowtie-json-schema/rust-jsonschema",
  "valid": true
}
{
  "implementation": "ghcr.io/bowtie-json-schema/js-ajv",
  "valid": null
}
{
  "implementation": "ghcr.io/bowtie-json-schema/js-hyperjump",
  "valid": true
}

Where the reasoning is likely easy to understand -- any implementation which implements unevaluatedItems by essentially doing a if additionalItems in instance: short_circuit() is forgetting that that needs to be if additionalItems in instance *and* items in instance: ... to comply with that ignore behavior.

The interesting bit here actually *only* applies to 2019, as it's the
only draft containing both unevaluatedItems as well as additionalItems
-- the latter in its specified behavior containing:

   if "items" is absent or its annotation result is the
   boolean true, "additionalItems" MUST be ignored.

(from https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02#section-9.3.1.2)

In newer drafts (i.e. 2020), when additionalItems "became" items, this
condition was dropped (i.e. items without a neighboring prefixItems now
is indeed *not* ignored).

Refs: https://github.com/orgs/json-schema-org/discussions/57

Closes: #292
@Julian Julian force-pushed the additionalItems-unevaluatedItems branch from e56aa91 to 52160b3 Compare February 21, 2023 15:02
Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

This exposed a bug in my implementation. It's now fixed and I successfully pass these tests.

@Julian
Copy link
Member Author

Julian commented Feb 22, 2023

Thanks!

@Julian Julian merged commit bf51b32 into main Feb 22, 2023
@Julian Julian deleted the additionalItems-unevaluatedItems branch February 22, 2023 08:28
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.

"unevaluatedItems", "additionalItems", and tuple "items"
2 participants