openapi-generator
openapi-generator copied to clipboard
[BUG][Java][okhttp] POST request with an empty body results in a NullPointerException
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Sending a POST request with an empty body results in a NullPointerException. This issue exists since version 5.3.1.
Unexpected exception thrown: java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.MediaType$Companion.parse, parameter $this$toMediaTypeOrNull
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.MediaType$Companion.parse, parameter $this$toMediaTypeOrNull
openapi-generator version
OpenAPI 5.4.0 and OpenAPI 5.3.1
OpenAPI declaration file content or url
see https://github.com/pg-fine/openapi-post-empty-body-bug
Generation Details
see https://github.com/pg-fine/openapi-post-empty-body-bug
Steps to reproduce
see https://github.com/pg-fine/openapi-post-empty-body-bug
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/commit/4ecceb13eae9ac33aa07e02851475b28b65652cf
"* remove default content-type in java okhttp client" is the reason for this bug
Suggest a fix
add a default content-type or allow empty request bodies with empty content-types.
add a default content-type or allow empty request bodies with empty content-types.
I prefer the latter. May I know if you can help contribute a fix for it?
I prefer the latter. May I know if you can help contribute a fix for it?
I also prefer the latter. My first suggestion would only be a quick fix and not solve the problem per se. Unfortunately, I have no idea how to fix this correctly since I have no overview of all implications a change would bring.
Hi there, did the problem resolved ?
Hello, is there already a new status regarding this issue?
This issue is resolved in 6.2.0. https://github.com/pg-fine/openapi-post-empty-body-bug/pull/1
Thanks for your help @fileme !