openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Java][okhttp] POST request with an empty body results in a NullPointerException

Open pg-fine opened this issue 2 years ago • 3 comments

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.

pg-fine avatar Mar 08 '22 16:03 pg-fine

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?

wing328 avatar Mar 08 '22 17:03 wing328

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.

pg-fine avatar Mar 09 '22 16:03 pg-fine

Hi there, did the problem resolved ?

QuyetVV2 avatar Aug 02 '22 06:08 QuyetVV2

Hello, is there already a new status regarding this issue?

codemolition22 avatar Dec 01 '22 14:12 codemolition22

This issue is resolved in 6.2.0. https://github.com/pg-fine/openapi-post-empty-body-bug/pull/1

fileme avatar Jan 19 '23 00:01 fileme

Thanks for your help @fileme !

pg-fine avatar Jan 19 '23 15:01 pg-fine