papsign / Ktor-OpenAPI-Generator

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

Overriding a primitive converter (UUID) #119

Open mplokita-figure opened 2 years ago

mplokita-figure commented 2 years ago

I'm hoping to override the default behavior of zeroing an invalid UUID string. (For example, I might prefer to throw an exception or return null.)

Does this constitute a new feature request?

primitive {
    try {
        UUID.fromString(it)
    } catch (e: IllegalArgumentException) {
        null
    } ?: UUID(0, 0)
}
Wicpar commented 2 years ago

you can use a nullable uuid parameter, it uses 0 as a default if you don't allow it to be null.

mplokita-figure commented 2 years ago

@Wicpar Won't that affect the API spec? If we would like to communicate to readers of the spec that the UUID is not optional, then is there an alternative solution?

Wicpar commented 2 years ago

You are right, there is no way to throw an error doing that, the correct implementation would be to remove the try-catch and have an exception handler catch and build a proper error response

aphu-figure commented 2 years ago

@Wicpar As far as overriding default converter behavior, I'm assuming this is still a viable solution? Any plans to incorporate this?

https://github.com/papsign/Ktor-OpenAPI-Generator/issues/82#issuecomment-733191825

Wicpar commented 2 years ago

I'll accept the PR if you make one :)