-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
OpenApi attribute nullable with enum #993
Comments
Interesting. I am not sure that this should be the expected behaviour. It is definitely possible to add null into the enum explicitly. Could you point to the OpenAPI doc that says that nullable should change the behaviour of enum? |
I couldn't find a doc or example so I asked OAI, essentially the response was validation constraints like enum should only apply when the value is not null. |
I've got a "fix" for this, if @epoberezkin is ok with calling the current behavior undesirable. For me the problem with the current behavior is that I cannot add The following fails as mentioned by the OP.
The next variation fails metaschema validation for the reason I mention above.
The final variation is not allowed for OpenAPI, which is the primary motivator for the
|
Sorry, which metaschema? You can put any values to enum - JSON Schema metaschema doesn’t have any requirement for item type. |
My apologies, I was conflating JSON Schema with a particular meta-schema that I was using. You are correct, there is no validation problem here inherent to JSON Schema. Well, I do have a solution coded up that obviates the need to explicitly add FWIW I do agree with @left-rite that it makes sense in the context of OpenAPI to implicitly allow |
@epoberezkin I realize you might still decide this is not an issue that AJV should handle differently than it currently does. No hard feelings if you ask me to close the PR I just opened. Thanks. |
I added the comment in PR before I saw it :) I don’t have a strong opinion - let’s see how OpenAPI addresses. |
Hello, What is the state of this issue? The format should be:
Note that null must be explicitly included in the list of enum values. Using nullable: true alone is not enough here. I tried this syntax in my swagger but Validation still fails: Is there any plan to fix this issue? Thanks, Joe |
It’s difficult to say why it doesn’t work with your Open API toolchain without the code sample, Ajv would definitely accept the schema - please test with Ajv directly without swagger OpenAPI clarified now that nullable is only extension of type keyword and it doesn’t change the behaviour of enum or anything else, so this issue should be closed. See OAI/OpenAPI-Specification#1900 (comment) The change they made is either merged or will be merged into 3.0.4 and definitely into 3.1 |
What version of Ajv are you using? Does the issue happen if you use the latest version?
6.10.0
Ajv options object
JSON Schema
Sample data
Your code
Validation result, data AFTER validation, error messages
What results did you expect?
The result to be true, since support for the keyword nullable has be set to true and schema has set nullable to true for the property "propertyOne".
Are you going to resolve the issue?
Not sure
The text was updated successfully, but these errors were encountered: