[BUG][JAVA] Content type of response seems to be ignored and always set to application/json
Description
The defined content type within the open api spec seems to be ignored. The generated code always contains "application/json".
openapi-generator version
openapi-generator-cli-4.3.1.jar
OpenAPI declaration file content or url
[...]
"200": {
"description": "Success",
"headers": {
"Cache-Control": {
"description": "Controls whether and how long response can be cached by consumers, defaults to 'no-cache, no-store'.",
"style": "simple",
"schema": {
"type": "string"
}
}
},
"content": {
"application/vnd.de.db.ris+json": {
"schema": {
"$ref": "#/components/schemas/BoardPublicArrival"
}
}
}
}
[...]
##### Command line used for generation
java -jar openapi-generator-cli-4.3.1.jar generate -g java -i swagger.yml --library native --api-package innoapi.api --invoker-package innoapi.invoker --model-package innoapi.model
##### Steps to reproduce
Look in the code and the accept header.
`
localVarRequestBuilder.header("Accept", "application/json");
`
##### Related issues/PRs
/
##### Suggest a fix
Content type has to evaulated for setting the accept header.
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
I face the same issue. Api is defined like this:
/output/{file}:
parameters:
- name: file
in: path
schema:
type: string
required: true
description: The filename of the converted file
get:
tags:
- subverter
operationId: getFile
summary: Get a file specified by file
responses:
200:
description: The converted file
content:
'binary/octet-stream': {}
But the generated Kotlin code insiste on adding application/json to both content-type and accept if not set explicilty: (in my case ApiClient.kt's request() function)
// take content-type/accept from spec or set to default (application/json) if not defined
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
requestConfig.headers[ContentType] = JsonMediaType
}
if (requestConfig.headers[Accept].isNullOrEmpty()) {
requestConfig.headers[Accept] = JsonMediaType
}
Isn't it possible to fetch the value for Accept by looking at the response."code".content?
@emongstad I think this belongs in a different issue as this is about the Java native template.
Content-Type and Accept are both having the same issue in Java native:
localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "application/json");
ok, I can agree on that. But I hope that if this is fixed for the java template, it will be fixed for e.g kotlin too?
I have the same issue, native java client always sets Accept header to application/json no matter the response type in the OpenAPI Spec YML
I ran into this problem today while working on a company project. I managed to develop a fix for this issue. I'm about to make a PR to integrate it. I hope this fix fully resolves the issue.