OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin] Wrong implicit Accept header sent when making requests to endpoint that expects HTTP 204
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
Description
When not specifying explicit header parameters the generated client will automatically add an Accept header application/json to all requests. This works nice in most cases but not when an endpoint returns 204, No content.
A request with Accept header application/json then results in HTTP 406 from the server
openapi-generator version
7.4.0
OpenAPI declaration file content or url
/test/property/{property_id}:
patch:
tags:
- 'property'
summary: 'Update property details'
description: 'Modify ''managedBy'' property value'
operationId: 'updateProperty'
parameters:
- $ref: '#/components/parameters/PropertyId'
requestBody:
content:
'application/vnd.xyz-0.1+json':
schema:
$ref: '#/components/schemas/PropertyUpdate'
responses:
'204':
description: 'Successful operation'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'406':
$ref: '#/components/responses/406'
'415':
$ref: '#/components/responses/415'
'500':
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
default:
$ref: '#/components/responses/GeneralError'
Generation Details
openApiGenerate {
generatorName.set("kotlin")
// Some irrelevant config details are omitted
with (configOptions) {
put("dateLibrary", "java17")
put("serializationLibrary", "kotlinx_serialization")
}
}
Suggest a fix
Whenever 204 is expected, provide the Accept header set to */* instead of application/json
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Kotlin client generated from the shown PATCH operation with the kotlinx_serialization library, then trace how request generation selects the Accept header for a 204 response. Verify the generated request behavior against the provided OpenAPI declaration, including the expected handling of explicit headers and the 204 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100