Skip to content
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

"unevaluatedItems" for arrays #557

Closed
handrews opened this issue Mar 5, 2018 · 1 comment
Closed

"unevaluatedItems" for arrays #557

handrews opened this issue Mar 5, 2018 · 1 comment

Comments

@handrews
Copy link
Contributor

handrews commented Mar 5, 2018

Issue #556 proposes an unevaluatedProperties keyword, together with the mechanisms for implementing it. This issue will only be considered if #556 is accepted.

Those same mechanisms (which should be debated in #556, and not here) could be used to define an unevaluatedItems keyword, based on an "evaluatedItems" annotation that is updated whenever "items" or "additionalItems" are successfully applied to an index.

Successful application of schema-form items or additionalItems (alongside the relevant array-form "items") would indicate that all array elements have been evaluated, and the "evaluatedItems" annotation ought to be able to convey that concisely.

additionalItems is used for things like positional function arguments where the first N arguments have specific types or structures, and an indefinite number of further positional arguments are allowed, all with the same type/structure. It's not exactly a common use case, but it is clear and has obvious parallels in numerous programing languages.

unevaluatedItems would be used in some sort of situation where, due to a oneOf or similar construct you will only know at runtime how long the prefix of individually typed elements will be.

{
  "type": "array",
  "oneOf": [
    {
      "items": [{"type": "object"}]
    },
    {
      "items": [{"type": "number"}, {"type": "boolean"}]
    }
  ],
  "unevaluatedItems": {"type": "string"}
}

As with unevaluatedProperties, unevaluatedItems is mainly useful in very large schemas, or schemas assembled out of many pieces. It is obviously trivial to refactor the schema above to use additionalProperties instead.

We don't have a lot of data on additionalItems and how (or how often) it is used, so it's hard to say how useful unevaluatedItems would be. But, once you're already implementing unevaluatedProperties it's not hard to add this, and the symmetry is appealing.

It would be interesting to find an example of schemas for systems involving complex sequential data.

@handrews
Copy link
Contributor Author

Done with #656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant