kora icon indicating copy to clipboard operation
kora copied to clipboard

OpenAPI generator - 400 Bad Request with body "data" if body is null

Open mitasov-ra opened this issue 2 years ago • 0 comments

I generated POST method from openapi and if I try to send a request with body "null" I get the following response:

HTTP/1.1 400 Bad Request
Connection: keep-alive
Server: kora/undertow
Content-Length: 4
Content-Type: text/plain; charset=utf-8
Date: Wed, 21 Jun 2023 07:21:42 GMT

data

I've already investigated and figured out that such strange answer is caused by NPE in ru.tinkoff.kora.json.module.http.server.JsonReaderHttpServerRequestMapper<T>:22:

    @Override
    public Mono<T> apply(HttpServerRequest request) {
        return ReactorUtils.toByteArrayMono(request.body())
            .handle((bytes, sink) -> {
                try {
                    sink.next(this.reader.read(bytes)); // <-- NPE HERE
                } catch (Exception e) {
                    var httpException = HttpServerResponseException.of(e, 400, e.getMessage());
                    sink.error(httpException);
                }
            });
    }

Text "data" came from HandleFuseableConditionalSubscriber#next:

data = Objects.requireNonNull(o, "data");

I'd be mush more better to allow null body and maybe even to generate validation messages similar to messages from JsonReader

mitasov-ra avatar Jun 21 '23 07:06 mitasov-ra