Skip to content

Support binary responses in Kotlin client #7204

@revmischa

Description

@revmischa
Description

Right now the Kotlin client doesn't support binary responses, only JSON.

openapi-generator version

5.0.0-beta

OpenAPI declaration file content or url

It is impossible to consume this response with Kotlin right now:

responses:
        '200':
          description: The generated PDF
          content:
            application/pdf:
              schema:
                type: string
                format: binary

Throws error responseBody currently only supports JSON body

Command line used for generation

Kotlin, gradle

Steps to reproduce

Make any request for a binary endpoint in Kotlin.

Related issues/PRs

Didn't see any.

Suggest a fix/enhancement

AbstractKotlinCodegen unfortunately maps the response type to java.io.File, which while convenient for sending a file request, is not well-suited to a response, because a File must refer to a file on disk.
It would be much preferable to change the type mapping to InputStream or something similar for the response only, but I couldn't figure out how to do this without breaking the request type mapping as well. Maybe there is some way to leverage the isResponseBinary property but it wasn't clear to me how to change this.

So I changed it to generate a tempfile in my PR. If we could make it be an InputStream that would be better, but it's not clear to me how.

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