Open krissrex opened 10 months ago
Seems to be issues with maps of ArrayList too. The keys will get a schema saying object
, not array.
I really wish it was possible to provide your own schemaGenerator
like in the OpenAPI2 implementation. I'm using a library which is able to produce Json schemas which work perfectly for my use case, but am unable to utilise them with http4k
Edit: the library is Kondor. See https://github.com/http4k/http4k/pull/1063
I really wish it was possible to provide your own schemaGenerator like in the OpenAPI2 implementation. I'm using a library which is able to produce Json schemas which work perfectly for my use case, but am unable to utilise them with http4k
This is possible - the creation of the Schema is abstracted behind the JsonSchemaCreator
interface which is used in both the OpenApi2 and OpenApi3 implementations.
I really wish it was possible to provide your own schemaGenerator like in the OpenAPI2 implementation. I'm using a library which is able to produce Json schemas which work perfectly for my use case, but am unable to utilise them with http4k
This is possible - the creation of the Schema is abstracted behind the
JsonSchemaCreator
interface which is used in both the OpenApi2 and OpenApi3 implementations.
@daviddenton I couldn't see a way to supply this in the OpenApi3 implementation. So I've submitted a PR for that here - https://github.com/http4k/http4k/pull/1058
I really wish it was possible to provide your own
schemaGenerator
like in the OpenAPI2 implementation. I'm using a library which is able to produce Json schemas which work perfectly for my use case, but am unable to utilise them with http4k
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: