Repository navigation
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
With the kotlin generator and jvm-okhttp4 (or jvm-okhttp3) library, the Accept header leaves out every media type that the client can't deserialize. This happens even when the success response is a binary file that the client never deserializes, because the return type is java.io.File.
If the success response only uses a type like application/gzip, and the error responses use application/json, the generated client sends:
localVariableHeaders["Accept"] = "application/json"Servers that do content negotiation reject this. They can't return the file as JSON, so the call fails before the client gets a response it can use.
Real-world example: the Norwegian Business Register (Brønnøysundregistrene) bulk download endpoint GET https://data.brreg.no/enhetsregisteret/api/enheter/lastned:
| Accept header sent | Result |
|---|---|
application/json (what the generated client sends) |
400 Bad Request |
application/gzip |
200 OK |
application/vnd.brreg.enhetsregisteret.enhet.v2+gzip, application/json (what it would send without the filter) |
200 OK |
openapi-generator version
7.27.0 (reproduced with openapi-generator-cli-7.27.0.jar). The same code is on current master (657c793). I don't know whether this is a regression.
OpenAPI declaration file content or url
Minimal spec:
openapi: 3.0.3
info:
title: Accept header repro
version: 1.0.0
paths:
/download:
get:
operationId: download
responses:
"200":
description: gzip file
content:
application/gzip:
schema:
type: string
format: binary
"400":
description: Bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Error:
type: object
properties:
message:
type: stringReal-world spec: the Brønnøysundregistrene Enhetsregisteret API, operation lastnedEnheter (docs: https://data.brreg.no/enhetsregisteret/api/dokumentasjon/no/index.html).
Generation Details
openapi-generator-cli generate -g kotlin --library jvm-okhttp4 -i spec.yaml -o out
Steps to reproduce
- Generate a client from the spec above.
- Look at
DefaultApi.downloadRequestConfig().
Actual:
localVariableHeaders["Accept"] = "application/json"Expected (all declared response media types):
localVariableHeaders["Accept"] = "application/gzip, application/json"If the spec has only the 200 response with application/gzip, the client sends no Accept header at all. That usually works, but only by accident.
Related issues/PRs
I didn't find an existing issue about this.
Suggest a fix
The filter is in KotlinClientCodegen.java:
operation.produces = operation.produces == null ? null : operation.produces.stream()
.filter(isSerializable)
.collect(Collectors.toList());The isSerializable check makes sense for consumes, where the client has to serialize a request body in that format. It doesn't make sense for produces, which only tells the server what the client accepts. Possible fixes:
- Don't filter
producesat all.ApiClient.responseBodyalready handlesFile,ByteArrayandStringregardless of media type. - Or skip the filter when the operation returns a file/binary (
operation.isResponseFile).
Activity
Inf1mum commentedon Nov 18, 2026
Taking this one — the jvm-okhttp4 Accept header drops non-JSON content types. A PR referencing this issue will follow.
fix(kotlin): list in Accept only response media types the okhttp4 cli…