Skip to content

[BUG][KOTLIN] jvm-okhttp4: Accept header drops non-JSON response media types, causing 400 on file downloads #25733

Open

Description

@nutgaard

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: string

Real-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
  1. Generate a client from the spec above.
  2. 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 produces at all. ApiClient.responseBody already handles File, ByteArray and String regardless of media type.
  • Or skip the filter when the operation returns a file/binary (operation.isResponseFile).

Activity

  1. Inf1mum commented on Nov 18, 2026

    @Inf1mum
    Contributor

    Taking this one — the jvm-okhttp4 Accept header drops non-JSON content types. A PR referencing this issue will follow.

  2. added a commit that references this issue on Nov 23, 2026
    005decc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions