Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Clarification needed: Why is an enum required to have at least one item? #110

Closed
arrkaye opened this issue Oct 18, 2019 · 2 comments
Closed

Comments

@arrkaye
Copy link

arrkaye commented Oct 18, 2019

And conversely, why is it invalid when a enum is [].

This is causing an issue for us when we generate schema's dynamically and there is an option that is meant to be unpopulated/empty.

Thanks.

@handrews
Copy link

@arrkaye Starting with draft-06, the requirement is "SHOULD have at least one element" (in draft-04 it was "MUST have at least one element"). SHOULD is a weaker requirement than MUST, and means that while it's not advised to have an empty array, it is legal. If you are using draft-06 or later and this is not working, then you should file an issue with the maintainer of your validator. If you're still using draft-04, I recommend finding a validator that supports a more recent draft.

@arrkaye
Copy link
Author

arrkaye commented Oct 21, 2019

Thanks for your reply @handrews

I'm looking at this line in the draft-06 meta-schema and it appears that the minItems for an enum array is set to 1.

Should that be 0/omitted, or have I misunderstood the intention of minItems in some way?

https://github.com/json-schema-org/json-schema-spec/blob/00e25c022514788dbb9161d52b70024f2646cfb5/schema.json#L133

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

No branches or pull requests

2 participants