Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
krzema12 opened this issue Aug 11, 2021 · 0 comments · Fixed by #10968
Closed
5 of 6 tasks

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

krzema12 opened this issue Aug 11, 2021 · 0 comments · Fixed by #10968

Comments

@krzema12
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant