You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If an OpenAPI specifies application/problem+json responses for 4xx or 5xx status codes, the generated interfaces will support JSON for the normal response, instead of only for error responses, even if the OpenAPI specifies only other media types for the normal 2xx response.
I tested this both for spring-boot and spring-http-interface, and it leads to some unwanted side-effects:
when a client calls the API with "Accept: application/problem+json", a service (using the generated classes) will attempt to create a JSON response even if the normal response is non-JSON, e.g. "image/png"
a client using the generated spring-http-interface, will specify "application/problem+json" in its Accept request header as preferred response content type, e.g. for a generated accept = { "application/problem+json", "image/png" }
#7141 : Code generation for Java client stubs using RestTemplate or WebClient was updated to exclude "application/problem+json" from "Accept" header during creation of requests.
The same solution isn't possible for spring-http-interface because it only has an interface, and the caller code is generated at runtime as a dynamic proxy.
Suggest a fix
For spring-http-interface, and for spring-boot with singleContentTypes: true, exclude application/problem+json from the list of content types in x-accepts in AbstractJavaCodegen.java#L1945.
For spring-boot with singleContentTypes: false, the produces variable would need to be filtered, but it is set in DefaultCodegen, so that might have a larger impact.
On a side note: setting the singleContentTypes to true doesn't seem to be effective: all content types are still included in the generated code; only sometimes in a different order.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
If an OpenAPI specifies
application/problem+json
responses for 4xx or 5xx status codes, the generated interfaces will support JSON for the normal response, instead of only for error responses, even if the OpenAPI specifies only other media types for the normal 2xx response.I tested this both for spring-boot and spring-http-interface, and it leads to some unwanted side-effects:
accept = { "application/problem+json", "image/png" }
openapi-generator version
Tested on 7.11, 7.12-SNAPSHOT and 8.0.0-SNAPSHOT
OpenAPI declaration file content or url
https://gist.github.com/pvdbosch/3b420281eaac355151370d30f7bfd192#file-openapi-yaml
The gist also contains the generated Java interfaces.
Generation Details
https://gist.github.com/pvdbosch/3b420281eaac355151370d30f7bfd192#file-pom-xml
Steps to reproduce
Generate code using provided OpenAPI.
Related issues/PRs
#7141 : Code generation for Java client stubs using RestTemplate or WebClient was updated to exclude "application/problem+json" from "Accept" header during creation of requests.
The same solution isn't possible for spring-http-interface because it only has an interface, and the caller code is generated at runtime as a dynamic proxy.
Suggest a fix
For spring-http-interface, and for spring-boot with
singleContentTypes: true
, excludeapplication/problem+json
from the list of content types inx-accepts
in AbstractJavaCodegen.java#L1945.For spring-boot with
singleContentTypes: false
, theproduces
variable would need to be filtered, but it is set inDefaultCodegen
, so that might have a larger impact.On a side note: setting the
singleContentTypes
totrue
doesn't seem to be effective: all content types are still included in the generated code; only sometimes in a different order.The text was updated successfully, but these errors were encountered: