-
-
Notifications
You must be signed in to change notification settings - Fork 249
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 3 schema generation is flawed for Maps #1036
Comments
Seems to be issues with maps of ArrayList too. The keys will get a schema saying |
I really wish it was possible to provide your own Edit: the library is Kondor. See #1063 |
This is possible - the creation of the Schema is abstracted behind the |
@daviddenton I couldn't see a way to supply this in the OpenApi3 implementation. So I've submitted a PR for that here - #1058 |
Mind sharing the name of the library? I might want to use it myself. |
There are several issues with the OpenApi schema generation, and I tried to fix them in my proof-of-concept repo at https://github.com/krissrex/http4k-openapi-annotations/blob/master/src/main/kotlin/no/krex/http4kopenapi/annotations/LifligAutoJsonToJsonSchema.kt . It seems to work, but the code feels slightly messy. (Not ready to PR anything).
The most important issues I found (and fixed) are these:
mapOf("key" to mapOf("keyInner" to 5))
->{ "additionalProperties": { "additionalProperties": { "type": "number} } }
.mapOf("key" to 1, "key2" to true)
->"additionalProperties": true
.The schema generation is based on the JSON, not the classes. And when a map gets its schema, the example keys are treated like object-properties, not example values, and fed into an
Object
schema asproperties
. Instead, we want the values of the example to inform the type ofadditionalProperties.type
. And if the inner values are maps, the schema should not beadditionalProperties.properties.additionalProperties
, butadditionalProperties.additionalProperties.type
.Example map:
Example of current (incorrect) schema:
Correct schema:
For maps of various types:
the correct is (not 100% sure about the
example
-property here):For maps of a primitive type:
the correct is:
The text was updated successfully, but these errors were encountered: