Description
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;
"contact_email": {
"type":["string","null"],
"format": ""
}
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 a null
value).
Abiding by Open API
When I have the following set;
"contact_email": {
"type":"string",
"nullable":true,
"format": ""
}
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 ownnullable
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,