Skip to content

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

Open
mitasov-ra opened this issue Jun 21, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working lang: java Related for Java language module: http-server Related to module - http-server

Comments

@mitasov-ra
Copy link
Contributor

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

@GoodforGod GoodforGod self-assigned this Jul 10, 2023
@GoodforGod GoodforGod added bug Something isn't working lang: java Related for Java language module: http-server Related to module - http-server labels Jul 10, 2023
@GoodforGod GoodforGod assigned Squiry and unassigned GoodforGod Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working lang: java Related for Java language module: http-server Related to module - http-server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants