JSON-Schema-Test-Suite icon indicating copy to clipboard operation
JSON-Schema-Test-Suite copied to clipboard

"unevaluatedItems" and "contains", "minContains", and "maxContains"

Open handrews opened this issue 6 years ago • 2 comments

This is a little vague in the spec, as discussed in https://github.com/json-schema-org/json-schema-spec/issues/810, but will be clarified in a bug fix and we should go ahead and test for it from the start.

contains gets applied to all elements of the array, and excludes any element to which it applied successfully from unevaluatedItems. This produces an interesting and potentially useful behavior of carving out exceptions in an otherwise homogenous array, which you can't otherwise do.

Given:

{
  "type": "array",
  "oneOf": [
    {
      "contains": {"type": "string"}
    },
    {
      "items": {"type": "integer"}
    }
  ],
  "unevaluatedItems": {"type": "boolean"}
}

The following instances should all be valid:

  • [ ] [true, "hello", false]
  • [ ] [1, 3, 4]
  • ~[true, false]~

Note that minContains and maxContains shouldn't affect this (although I don't think there's any meaningful interaction with maxContains as matching less is no different than if it's not there, and matching more causes it to fail validation):

  • [ ] if contains matches more than the minimum, all of those should be excluded from unevaluatedItems, not just the first however many up to the minimum

handrews avatar Oct 20 '19 23:10 handrews

If [true, false] doesn't satisfy the oneOf, shouldn't it be considered invalid? (per https://github.com/json-schema-org/json-schema-spec/issues/810#issuecomment-581621587)

ssilverman avatar Apr 25 '20 04:04 ssilverman

@ssilverman is correct here (given the edit in the linked ticket), so removing that example ([true, false]), will see if we already have tests for the other two, I think we may.

Julian avatar Jul 06 '22 10:07 Julian

No further tests are needed. Closing this.

gregsdennis avatar Apr 15 '24 23:04 gregsdennis