papsign / Ktor-OpenAPI-Generator

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

fix npe when missing required field #75

Closed inaiat closed 3 years ago

inaiat commented 3 years ago

see issue 74

Wicpar commented 3 years ago

Thanks for your contribution

ryu1kn commented 3 years ago

This should let me handle validation errors differently from other errors with ease. Wondering when this change becomes available as a release, @Wicpar ? Thanks!

Wicpar commented 3 years ago

oh, right, the release...

msramosjr commented 3 years ago

This PR apparently broke the optional query param feature. I have run the example in Minimal.kt and when calling /string/{a} without the optional query param I got this error:

17:03:28.673 [nioEventLoopGroup-4-3] ERROR ktor.application - Unhandled: GET - /string/123
com.papsign.ktor.openapigen.exceptions.OpenAPIRequiredFieldException: The field optional is required
    at com.papsign.ktor.openapigen.parameters.handlers.ModularParameterHandler.parse(ModularParameterHandler.kt:32)
    at com.papsign.ktor.openapigen.route.OpenAPIRoute$handle$$inlined$apply$lambda$1$1.invokeSuspend(OpenAPIRoute.kt:63)
    at com.papsign.ktor.openapigen.route.OpenAPIRoute$handle$$inlined$apply$lambda$1$1.invoke(OpenAPIRoute.kt)

The code in Minimal.kt:

@Path("string/{a}")
    data class StringParam(
        @PathParam("A simple String Param") val a: String,
        @QueryParam("Optional String") val optional: String? // Nullable Types are optional
    )

My code is similar to this one and also have broken.

Wicpar commented 3 years ago

right, forgot about this peculiar thing...