json-schema-org/understanding-json-schema

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

arrkaye opened this issue · 2 comments

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.

@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.

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