cdimascio / openapi-spring-webflux-validator

🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Other
97 stars 13 forks source link

Support parameterized types in withBody #24

Closed zambrovski closed 3 years ago

zambrovski commented 3 years ago

As a developer I want to be able to specify a type of body if this is a parameterized type erased by Java in runtime.

Here is an example from the handler function:

    request
      .bodyToMono(object : ParameterizedTypeReference<List<SomeBodyElement>>() {})
      .flatmap {
         ...
      }.flatMap {
        ServerResponse.created(request.uri()).contentType(MediaType.APPLICATION_JSON).build()
      }.onErrorResume {
        ServerResponse.badRequest().bodyValue(ErrorDto(it))
      }

In this case, the usage of Class<T>is not desirable, since it would be List.class that lacks the element type information failing to infer the type inside the handler function (T) -> ServerResponse.

cdimascio commented 3 years ago

@zambrovski this (along with your other changes) are in v3.3.0. thank you for your work! (note: the 3.3.0 is already on jcenter. can take some time to reach mavencentral)