-
Notifications
You must be signed in to change notification settings - Fork 356
Possible solution for nullable support #551
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
@jb0o I'm not overly familiar with OpenAPI, so this may not be applicable - but would moving the "contact_email": {
"anyOf": [
{ "type": "string", "format": "" },
{ "type": "null" }
]
} This ensures that the If it is useful for documentation generation, you could also add "contact_email": {
"nullable": true,
"anyOf": [
{ "type": "string", "format": "" },
{ "type": "null" }
]
} JSON Schema will simply ignore unknown keywords, so |
Further to the above - if you don't want to make manual changes to your schema, the transformation I suggested is trivial to carry out in a preprocessor, as it's just a simple rearrangement. |
@jb0o in an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume this is a rather old issue, which sadly was left unanswered, and can be closed? Feel free to close it yourself with some comments if helpful. |
Hi all,
Great package, definitely the best out there for the structure and data type validation I've needed, however theres one issue I currently have which I hope you could provide some guidance one. Its not your actual issue, but one I hope that I could be pointed in the right direction as to the possible solutions.
I'm currently using Redoc for my static documentation generator, which is great. However this uses the Open API spec, which as much may be similar to JSON Schema, does actually diverge, and I'm facing the exact same issue that is documented in this blog post: https://philsturgeon.uk/api/2018/03/30/openapi-and-json-schema-divergence/
Essentially, I have a number of
nullable
parameters and I need to be able to have them properly validated against and documented on.Abiding by JSON Schema
When I have the following set;
this pleases the JSON schema fine, but spoils the rendering within the API docs. (its prints the datatype as
stringnull
and all example request fields show as anull
value).Abiding by Open API
When I have the following set;
this pleases the API docs, but rightfully breaks the JSON Schema validation when some of my responses go through, as the null value isn't adhered too, which is correct as per the JSON schema.
So I'm left with a number of options;
Move validator to Open API spec
I've had a play about with some, and none of them seem to be any good.
Move docs
Same as above but with the documentation rendering. If you know of any decent JSON Schema automated documentation, please let me know.
Fork JSON Schema project
I could fork this project and add in support for an OpenAPI adapter to convert any of the given data into Open API spec
Pre-process the schema
I could pre-process the schema to ensure all nullable entries are included as part of the type prop and not its own
nullable
prop.I've probably answered my own question about with a number of answers so I'm keen to understand if anyone has experienced this and how they got around it.
Thanks all,
The text was updated successfully, but these errors were encountered: