Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10130
Closed
Open
Issue created Aug 11, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Kotlin][Multiplatform] Content-Type is not customizable when fetching files

Created by: krzema12

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

I'm trying to fetch image files using the generated client. It ends up with:

io.ktor.client.features.ClientRequestException: Client request(https://<redacted manually>) invalid: 406 . Text: ""

When I modify the ApiClient like so:

    private val client: HttpClient by lazy {
        val jsonConfig: JsonFeature.Config.() -> Unit = {
            this.serializer = this@ApiClient.serializer
            accept(ContentType("image", "jpeg"))  // <<<<<<<<<<<<<<<<<<<< ADDED
            accept(ContentType("image", "png"))  // <<<<<<<<<<<<<<<<<<<< ADDED
        }
        val clientConfig: (HttpClientConfig<*>) -> Unit = { it.install(JsonFeature, jsonConfig) }
        httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig)
    }

It works as expected in my case.

openapi-generator version

5.2.0. I don't know if it ever worked before, so not sure if it's a regression.

OpenAPI declaration file content or url

See responses and allowed content - OpenAPI is aware that some APIs expect certain content types.

    "/rest/external/v1/employees/{selector}/profile-picture": {
      "get": {
        "summary": "...",
        "description": "...",
        "operationId": "getProfilePicture",
        "parameters": [
          {
            "name": "selector",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Found",
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
Generation Details
openApiGenerate {
    generatorName.set("kotlin")
    library.set("multiplatform")
    // ...
}
Steps to reproduce
  1. Generate a client for an API that fetches e.g. JPG or PNG images.
  2. Try to call such API using the client.
Related issues/PRs

Not found.

Suggest a fix

Looking at OpenAPI declaration file, information about content types requested by a given API is given there. It's a matter of using it in the code somehow. Customization of content types per API would be good to have, to not list all possible content types in a single place.

Assignee
Assign to
Time tracking