Skip to content

"unevaluatedItems" and single-schema "items" #291

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

Closed
3 tasks
handrews opened this issue Oct 20, 2019 · 5 comments · Fixed by #317
Closed
3 tasks

"unevaluatedItems" and single-schema "items" #291

handrews opened this issue Oct 20, 2019 · 5 comments · Fixed by #317
Assignees
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.
Milestone

Comments

@handrews
Copy link
Contributor

handrews commented Oct 20, 2019

unevaluatedItems should apply if there is a single-schema items which fails to apply. Conversely, unevaluatedItems should be ignored if a single-schema items applies successfully.

Given the following:

{
  "unevaluatedItems": {"type": "boolean"},
  "anyOf": [
    {
      "items": {"type": "string"}
    },
    true
  ]
}
  • [true, false] should pass
  • ["yes", "no"] should pass
  • ["yes", false] should fail
@handrews handrews added this to the 2019-09 milestone Oct 20, 2019
@Julian Julian added the missing test A request to add a test to the suite that is currently not covered elsewhere. label Nov 29, 2019
@Relequestual Relequestual self-assigned this Dec 12, 2019
@Relequestual
Copy link
Member

Relequestual commented Dec 12, 2019

In the above example, wouldn't [true, false] pass regardless of unevaluatedProperties having a type of boolean?

Would it therefore be correct to have the test schema second anyOf schema be items: const: true?

Nevermind, I think I GET it now. It's checking the annotation result is actually what matters, because unevaluatedItems still needs to be applied, and will return false, causing the overall validation process to fail.

@gregsdennis
Copy link
Member

gregsdennis commented Dec 12, 2019

This is interesting in the first and third test cases because although #/anyOf/1 validates that the instance as a whole is valid, it still doesn't visit the items, which unevaluatedItems then must handle. Also of note is that although #/anyOf/0 technically visits the items, it fails, so it doesn't return any annotations that it visited them, so they remain in an "unchecked" state.

For the second case, #/anyOf/0 visits the items, so unevaluatedItems doesn't need to.

@gregsdennis
Copy link
Member

gregsdennis commented Dec 12, 2019

@Relequestual encouraged me to create some debug logging to show how my implementation was making its decisions. I quickly worked something up for this example (since it only has four keywords to update). Here are the results:

[true, false]

[00:00.008965]: Begin validation of # by #
[00:00.012577]: Processing `anyOf`
[00:00.014493]: Begin validation of # by #/anyOf/0
[00:00.014617]: Processing `items`
[00:00.016531]: items is an single subschema; process all elements
[00:00.016559]: Evaluating index: 0
[00:00.016567]: Begin validation of #/0 by #/anyOf/0/items
[00:00.016671]: Processing `type`
[00:00.023226]: Validating that instance is of type "string"
[00:00.023261]: Type check failed: found boolean
[00:00.024745]: `type` complete: invalid
[00:00.024943]: Validation of #/0 by #/anyOf/0/items complete: invalid
[00:00.025009]: Evaluating index: 1
[00:00.025015]: Begin validation of #/1 by #/anyOf/0/items
[00:00.025034]: Processing `type`
[00:00.025047]: Validating that instance is of type "string"
[00:00.025050]: Type check failed: found boolean
[00:00.025076]: `type` complete: invalid
[00:00.025084]: Validation of #/1 by #/anyOf/0/items complete: invalid
[00:00.025191]: `items` complete: invalid
[00:00.025209]: Validation of # by #/anyOf/0 complete: invalid
[00:00.025216]: anyOf valid: False
[00:00.025229]: Begin validation of # by #/anyOf/1
[00:00.025231]: `true` schema; all instances valid
[00:00.025233]: anyOf valid: True
[00:00.025639]: `anyOf` complete: valid
[00:00.025699]: Processing `unevaluatedItems`
[00:00.026596]: No indices have been evaluated; process all
[00:00.032879]: Evaluating index: 0
[00:00.032909]: Begin validation of #/0 by #/unevaluatedItems
[00:00.032925]: Processing `type`
[00:00.032943]: Validating that instance is of type "boolean"
[00:00.032945]: `type` complete: valid
[00:00.032949]: Validation of #/0 by #/unevaluatedItems complete: valid
[00:00.032954]: Evaluating index: 1
[00:00.032959]: Begin validation of #/1 by #/unevaluatedItems
[00:00.032968]: Processing `type`
[00:00.032973]: Validating that instance is of type "boolean"
[00:00.032977]: `type` complete: valid
[00:00.032980]: Validation of #/1 by #/unevaluatedItems complete: valid
[00:00.032992]: `unevaluatedItems` complete: valid
[00:00.032995]: Validation of # by # complete: valid

["yes", "no"]

[00:00.053291]: Begin validation of # by #
[00:00.053334]: Processing `anyOf`
[00:00.053353]: Begin validation of # by #/anyOf/0
[00:00.053360]: Processing `items`
[00:00.053368]: items is an single subschema; process all elements
[00:00.053376]: Evaluating index: 0
[00:00.053382]: Begin validation of #/0 by #/anyOf/0/items
[00:00.053387]: Processing `type`
[00:00.053400]: Validating that instance is of type "string"
[00:00.053799]: `type` complete: valid
[00:00.053809]: Validation of #/0 by #/anyOf/0/items complete: valid
[00:00.053820]: Evaluating index: 1
[00:00.053823]: Begin validation of #/1 by #/anyOf/0/items
[00:00.053830]: Processing `type`
[00:00.053838]: Validating that instance is of type "string"
[00:00.053855]: `type` complete: valid
[00:00.053859]: Validation of #/1 by #/anyOf/0/items complete: valid
[00:00.053860]: `items` complete: valid
[00:00.053866]: Validation of # by #/anyOf/0 complete: valid
[00:00.053868]: anyOf valid: True
[00:00.053882]: Begin validation of # by #/anyOf/1
[00:00.053883]: `true` schema; all instances valid
[00:00.053902]: anyOf valid: True
[00:00.053905]: `anyOf` complete: valid
[00:00.053906]: Processing `unevaluatedItems`
[00:00.053916]: indices up to 1 have been evaluated; skipping these
[00:00.053918]: All items have been validated
[00:00.053919]: `unevaluatedItems` complete: valid
[00:00.053926]: Validation of # by # complete: valid

["yes", false]

[00:00.054175]: Begin validation of # by #
[00:00.054192]: Processing `anyOf`
[00:00.054199]: Begin validation of # by #/anyOf/0
[00:00.054203]: Processing `items`
[00:00.054209]: items is an single subschema; process all elements
[00:00.054213]: Evaluating index: 0
[00:00.054216]: Begin validation of #/0 by #/anyOf/0/items
[00:00.054220]: Processing `type`
[00:00.054230]: Validating that instance is of type "string"
[00:00.054234]: `type` complete: valid
[00:00.054237]: Validation of #/0 by #/anyOf/0/items complete: valid
[00:00.054241]: Evaluating index: 1
[00:00.054243]: Begin validation of #/1 by #/anyOf/0/items
[00:00.054250]: Processing `type`
[00:00.054255]: Validating that instance is of type "string"
[00:00.054259]: Type check failed: found boolean
[00:00.054286]: `type` complete: invalid
[00:00.054291]: Validation of #/1 by #/anyOf/0/items complete: invalid
[00:00.054297]: `items` complete: invalid
[00:00.054299]: Validation of # by #/anyOf/0 complete: invalid
[00:00.054300]: anyOf valid: False
[00:00.054306]: Begin validation of # by #/anyOf/1
[00:00.054307]: `true` schema; all instances valid
[00:00.054308]: anyOf valid: True
[00:00.054315]: `anyOf` complete: valid
[00:00.054316]: Processing `unevaluatedItems`
[00:00.054318]: No indices have been evaluated; process all
[00:00.054398]: Evaluating index: 0
[00:00.054414]: Begin validation of #/0 by #/unevaluatedItems
[00:00.054420]: Processing `type`
[00:00.054428]: Validating that instance is of type "boolean"
[00:00.054432]: Type check failed: found string
[00:00.054446]: `type` complete: invalid
[00:00.054450]: Validation of #/0 by #/unevaluatedItems complete: invalid
[00:00.054452]: Evaluating index: 1
[00:00.054457]: Begin validation of #/1 by #/unevaluatedItems
[00:00.054465]: Processing `type`
[00:00.054470]: Validating that instance is of type "boolean"
[00:00.054471]: `type` complete: valid
[00:00.054474]: Validation of #/1 by #/unevaluatedItems complete: valid
[00:00.054666]: `unevaluatedItems` complete: invalid
[00:00.054674]: Validation of # by # complete: invalid

(also, my implementation has a few bugs. update pending)

@Relequestual
Copy link
Member

These tests may be impacted by json-schema-org/json-schema-spec#810

1 similar comment
@Relequestual
Copy link
Member

These tests may be impacted by json-schema-org/json-schema-spec#810

Julian pushed a commit to Relequestual/JSON-Schema-Test-Suite that referenced this issue Jun 30, 2022
Julian added a commit that referenced this issue Jun 30, 2022
Add tests for Single-schema items and unevaluatedItems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants