-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[Question/Clarification] Is enum with empty list of values considered to be valid OAS3 schema? #2737
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
Comments
No, the enum array may be empty:
https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1.2 |
Thanks for the pointer @karenetheridge , misread your original response, so updating the comment. |
Looks like you might have hit an edge case with validation tools. OAS3 depends on "draft 6" which was intended to be re-release of "draft 4" as "draft 4" was expired at the time. It was our understanding that those two versions were pretty much the same. Looking at the Interesting enough, the migration guide between those two versions doesn't even mention the difference in the While less than ideal, given the amount of values you're referring to and the fact you mentioned the list is actually dynamic - you might want to consider this as an open value field instead of specifying it as an empty |
Thanks a lot for the feedback @webron , i do feel that either representation 'is not quite right'.
It feels more clear that the second one is not an ordinary string type but rather something bounded by a set of values. Granted that either representation would still need additional information to convey / point to a source which describes the list of available values. Are there any drawbacks from using the empty enum[] for this usecase? |
Not entirely sure that's how json schema actually works, but the way I read an empty enum - no value is valid and validators would blow on any value to that field. You might think that doesn't make sense because why would anyone define something like that, but it's actually quite easy to write json schemas where nothing would validate against them (not a criticism just a mention of facts). |
Thanks again for the feedback @webron , want to make sure i understand your point. 'the way I read an empty enum - no value is valid and validators would blow on any value to that field' So you are saying if i used the generated schema (which has an 'enum []' definition) and used a valid json input which has any value in that field even when the value provided is from the specified/valid set which we point a consumer to be it via info inside the description field or some other means that Json would fail validations against the schema because the enum set is empty. |
Correct. That said, @karenetheridge is definitely more knowledgeable about JSON Schema than me, and she can give you a more accurate answer. |
Sounds good, thanks again for clarifications and input which was very helpful @webron , @karenetheridge |
Uh oh!
There was an error while loading. Please reload this page.
Newbie to this, so my apologies if this is not the right format/forum please advise what would be a better way to ask/clarify.
We are building an OAS representation for an existing 20 year old API which comes with some quirks and challenges. One of the challenges is around expressing Schemas with field data types which represented on the backend as Enums/Picklist data types. The challenge is multifold:
Combined this has a potential for blowing up the overall size of schema which we are hoping to avoid.
As one of the solutions we were considering mapping those types to an Enum with an empty set, and adding a description with a pointer to the doc/API which can be used to obtain the list of possible values. But currently looks like some of the existing validators flag this as an invalid OAS3 schema. I tried looking through the OAS3 spec documentation but it does not mention anywhere that enum must have at least one item, so was wondering if there is such limitation?
The text was updated successfully, but these errors were encountered: