ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
141 stars 85 forks source link

[BUG][Hydra][Java] ApiClient.buildRequest using PUT method with no request body leads to exception #191

Closed lrenard-qima closed 1 year ago

lrenard-qima commented 2 years ago

Preflight checklist

Describe the bug

Exception when trying to accept LogoutRequest using Hydra ApiClient.

A corresponding bug has been fixed on openapi-generators side : Link to the issue : https://github.com/OpenAPITools/openapi-generator/issues/12143 Link to the fix : https://github.com/OpenAPITools/openapi-generator/pull/12172

Since Hydra ApiClient is generated, it would certainly fix the issue to upgrade to fixed openapi version and generate new ApiClient.

Breaks in sh.ory.hydra.ApiClient line 1251 at :

// use an empty request body (for POST, PUT and PATCH)
reqBody = RequestBody.create("", MediaType.parse(contentType));

Reproducing the bug

Steps to reproduce :

1) Create Java project using hydra-client-java 2) Create a Hydra AdminApi using ApiClient 3) Call AdminApi acceptLogoutRequest

Relevant log output

java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.MediaType$Companion.parse, parameter $this$toMediaTypeOrNull
    at okhttp3.MediaType$Companion.parse(MediaType.kt) ~[okhttp-4.9.3.jar:na]
    at okhttp3.MediaType.parse(MediaType.kt) ~[okhttp-4.9.3.jar:na]
    at sh.ory.hydra.ApiClient.buildRequest(ApiClient.java:1225) ~[hydra-client-1.11.7.jar:na]
    at sh.ory.hydra.ApiClient.buildCall(ApiClient.java:1181) ~[hydra-client-1.11.7.jar:na]
    at sh.ory.hydra.api.AdminApi.acceptLogoutRequestCall(AdminApi.java:449) ~[hydra-client-1.11.7.jar:na]
    at sh.ory.hydra.api.AdminApi.acceptLogoutRequestValidateBeforeCall(AdminApi.java:461) ~[hydra-client-1.11.7.jar:na]
    at sh.ory.hydra.api.AdminApi.acceptLogoutRequestWithHttpInfo(AdminApi.java:500) ~[hydra-client-1.11.7.jar:na]
    at sh.ory.hydra.api.AdminApi.acceptLogoutRequest(AdminApi.java:481) ~[hydra-client-1.11.7.jar:na]

Relevant configuration

No response

Version

1.11.7

On which operating system are you observing this issue?

No response

In which environment are you deploying?

No response

Additional Context

No response

jonas-jonas commented 1 year ago

Hi, thanks for the report & the PR. We updated generator version, so the latest releases should resolve this issue. If the issue persists, please re-open this issue.