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

Bug - Response is 200 for empty body #3

Closed marcinziolo closed 5 years ago

marcinziolo commented 5 years ago

If I send empty body. In the following code json will be empty mono, flatMap won't be invoked at all, therefore validation and handler won't be invoked too. Endpoint returns empty body with 200 http status code.

        fun validate(handler: (T) -> Mono<ServerResponse>): Mono<ServerResponse> {
            val success = { json: String -> objectMapperFactory().readValue(json, bodyType) }
            val json = request.body(BodyExtractors.toMono(String::class.java))
            return json.flatMap { validator.validate(request, it) ?: handler(success(it)) }
        }
marcinziolo commented 5 years ago

Here is PR with the fix. Could you take a look on it?

cdimascio commented 5 years ago

thanks for the fix! its live in v2.1.1

marcinziolo commented 5 years ago

Thanks for the super quick release.