swagger-api / swagger-api/swagger-codegen
[kotlin] OkHttpClient is not customizable.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
There is no chance to access response headers because
- It is impossible to add
interceptorsto OkHttpClient headersonApiInfrastructureResponseis ignored .
open class ApiClient(val baseUrl: String) {
companion object {
@JvmStatic
val client : OkHttpClient = OkHttpClient() // No chance to customize OkHttpClient
}
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType) {
abstract val statusCode: Int
abstract val headers: Map<String,List<String>> // Set, but not be used anywhere.
}
// api.mustache
return when (response.responseType) {
// Only use data property, headers is ignored.
ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
else -> throw kotlin.IllegalStateException("Undefined ResponseType.")
}
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/7602
Suggest a fix/enhancement
I think it would be better to set user customized OkHttpClient.Builder to ApiClient.Companion instead of OkHttpClient. I will try to fix these.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin ApiClient and ApiInfrastructureResponse examples, then inspect api.mustache where the response is converted to the return value. Trace how OkHttpClient is created and how response headers are represented. Done means a generated client can use a customized OkHttpClient.Builder and response headers are no longer ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100