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
Content-Type in request response is not respected in generated Java Native client.
Generated Java Native client is mapping all response body into ObjectMapper causing databind Exceptions.
See api.mustache line 278
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {}) // closes the InputStream
openapi-generator version
found in openapi-generator-7.6.0.jar, retestet with current master.
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Example
version: 1.0.0
servers:
- url: "http://localhost:3000"
paths:
"/example":
get:
responses:
'200':
description: example response
content:
text/csv:
schema:
type: string
components:
schemas:
Example:
title: Example
description: Example
type: object
properties:
name:
type: string
pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$'
Having YAML with Response other than application/json
responses:
'200':
description: OK
content:
text/csv:
schema:
type: string
generate NATIVE (-g java --library native) Java client with with CLI Generator.
Produced Api Class operation snipped (exampleGetWithHttpInfo())
[CUT]
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("exampleGet", localVarResponse);
}
return new ApiResponse<String>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<String>() {}) // closes the InputStream
);
} finally {
}
[CUT]
In generated code (DefaultApi.java) there is not Content-Type specific response mapping. The current code assumes all responses are application/json and processing by ObjectMapper causing exceptions.
In Jersey2 and Jersey3 it is handled correctly.
Call exampleGetWithHttpInfo() on an endpoint providing some string and content-type other than application/json.
Related issues/PRs
Not known.
Suggest a fix
Jersey2 and Jersey3 has correct Content-Type handling.
Just implement the deserialise as in Jersey3:
Bug Report Checklist
Description
Content-Type in request response is not respected in generated Java Native client.
Generated Java Native client is mapping all response body into ObjectMapper causing databind Exceptions.
See api.mustache line 278
openapi-generator version
found in openapi-generator-7.6.0.jar, retestet with current master.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Having YAML with Response other than application/json
generate NATIVE (-g java --library native) Java client with with CLI Generator.
Produced Api Class operation snipped (exampleGetWithHttpInfo())
In generated code (DefaultApi.java) there is not Content-Type specific response mapping. The current code assumes all responses are application/json and processing by ObjectMapper causing exceptions.
In Jersey2 and Jersey3 it is handled correctly.
Call exampleGetWithHttpInfo() on an endpoint providing some string and content-type other than application/json.
Related issues/PRs
Not known.
Suggest a fix
Jersey2 and Jersey3 has correct Content-Type handling.
Just implement the deserialise as in Jersey3:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache
If needed I can contribute by fixing this bug (adopt mustache templates / create patch)
The text was updated successfully, but these errors were encountered: