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

Optional array items (object-like validation with order) #19

Open
MAProsper opened this issue Jun 29, 2019 · 3 comments
Open

Optional array items (object-like validation with order) #19

MAProsper opened this issue Jun 29, 2019 · 3 comments

Comments

@MAProsper
Copy link

It would be useful to have a tuple validation with optional items, it could act similarly to the object's keyword properties but with forced order.

So for example if the schema mandated first the number 1 followed by 2, it could match any combination of them (missing or present) except for a 2 followed by a 1; since even though they are valid items the schemas which validated them are not in order.

This could be implemented reusing the required keyword for arrays, which could contain an array of item indices. Additionally it could also be set to true specifying all items are required (acting like tuple validation) or false marking all items as optional. If not present it can be assumed to be true for backward compatibility reasons or following the behaviour in objects false.

The exact behaviour might be better off following the result of json-schema-org/json-schema-spec#659.

@Relequestual
Copy link
Member

What's the use case here? Why do you want to be able to check this?

@MAProsper
Copy link
Author

MAProsper commented Jul 2, 2019

List validation currently seems to act as a set validation, since order is not taken into account, but it gives flexibility in terms of the array length. Tuple validation however takes the order into consideration, but forces a fixed number of items to be present, with additionalItems just concatenating the set validation. Implementing it would allow for a more flexible but order persistent array validation, similar to actual lists.

It's inclusion would re-enable a similar behavior to the one present in Draft-03; allowing additional items to be present at specific positions instead of at the end without order. Additionally when setting all items to optional it would enable arrays to contain an arbitrary amount of items while still being order by a certain criteria.

@handrews
Copy link
Contributor

Moving keyword proposals without clear immediate support into the vocabularies repository.

@handrews handrews transferred this issue from json-schema-org/json-schema-spec Feb 28, 2020
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

No branches or pull requests

3 participants