Open LukasForst opened 2 years ago
To be honest this is not an open API generator issue. It is mostly related to generic types information erasure at runtime. Jackson can't get generic type information so it is not able to propper parse this type. This will not work for top-level generic objects. But it should be fine for such a case.
class UuidsList(val values: List<UUID>
But this will require changing payload from list of uuids, to object that contains a list of UUIDs
Another solution will be to use post "x-www-form-urlencoded" content type with key-value pairs. But this will look exactly the same as the previous example (UuidsList)
We can use inheritance to preserve generic type at runtime, But unfortunately, this will not work out of the box as code from DefaultCollectionSchemaProvider needs to be adjusted as for now it only handles current class generic arguments without supertype support.
class UuidsList: ArrayList<UUID> { }
I have created some dirty working solution https://github.com/kkalisz/Ktor-OpenAPI-Generator/tree/generic_parameters https://github.com/kkalisz/Ktor-OpenAPI-Generator/blob/generic_parameters/src/test/kotlin/com/papsign/ktor/openapigen/TopLevelGenericObjectRequestTest.kt
post
fails to deserialiseList<UUID>
in body, even though Swagger knows that the correct type isUUID
. Kotlin says it'sUUID
, however during runtime, it'sString
, which results inClassCastException
when accessing the element. My project is using latest Jackson.Minimal working example:
Request:
Debugger:
Exception:
And the
openapi.json