[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
- Generate a client for an API that fetches e.g. JPG or PNG images.
- 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.