papsign / Ktor-OpenAPI-Generator

Ktor OpenAPI/Swagger 3 Generator
Apache License 2.0
241 stars 42 forks source link

Date and date-time support #82

Closed Aschraf closed 3 years ago

Aschraf commented 3 years ago

Hello,

I'm currently using this great library and I'm not sure how to handle date-time string type (out of an Instant or Date java object).

From what I see, It was removed from PrimitiveConverter:

https://github.com/papsign/Ktor-OpenAPI-Generator/blob/9c8a8430d99d13728db126170fc8e142a2fdcda9/src/main/kotlin/com/papsign/ktor/openapigen/parameters/parsers/converters/primitive/PrimitiveConverter.kt#L52

Are there any plans to reintroduce support for dates? Or is it possible to do it some other way?

Wicpar commented 3 years ago

that part is not directly modular, so not much you can do as a quick fix...

If you can handle the types properly as ISO DateTime Strings it would be a great PR.

An alternative is to add a hook for injecting custom converters in ConverterFactory.Companion by extending ConverterSelectorFactory with something like injectConverterBefore(KClass, ConverterSelector) injectConverterAfter(KClass, ConverterSelector) removeConverter(KClass) KClass being one of the converter handler objects classes

A bit ugly, it being static, but i see no better way to get it done for the way the library is used.

Wicpar commented 3 years ago

Merged, released.