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
  • #12444
Closed
Open
Issue created May 24, 2022 by Administrator@rootContributor

[Kotlin] [Feature] OkHttpClient - replacing static client usage with client Injection

Created by: tihonovgn

Is your feature request related to a problem? Please describe.

I need to use different interceptors for different api clients in a project. In the current implementation, I can only add an interceptor through the static field ApiClient.builder. In this case, all clients use the same interceptors.

@JvmStatic val builder: OkHttpClient.Builder = OkHttpClient.Builder()

Describe the solution you'd like

It would be nice to be able to inject your own instance of the OkHttpClient class into the API client constructor.

class V1Api(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = ApiClient.defaultClient) : ApiClient(basePath) {

fun getOrdersClient(): V3Api {
    val builder = OkHttpClient.Builder()
    builder.addInterceptor(
        dbLoggerInterceptor
    )
    return V3Api(baseURL, builder.build())
}

fun getPickupsClient(): V3Api {
    val builder = OkHttpClient.Builder()
    builder.addInterceptor(
        kibanaLoggerInterceptor
    )

    return V3Api(baseURL, builder.build())
}

@jimschubert @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m

Assignee
Assign to
Time tracking