OpenAPITools / OpenAPITools/openapi-generator

[REQ] Allow to pass OkHttpClient into ApiClient constructor

Open
#5,259 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The problem

Right now ApiClient for language java and library okhttp-gson is generated so that it always create a new OkHttpClient, which is not efficient. And it also recommended to have shared instance of OkHttpClient
In my app I'm go to call API, which is the same for different hosts, so I'm enforced to create ApiClient per host. And it creates OkHttpClient per host, which is I want to avoid.

Also it would be great to have possibility to provide own implementation for authentication.

Suggestion

Make it possible to pass OkHttpClient into constructor of ApiClient. Or maybe just not to instantiate it in ApiClient at all and set it via setter. But it's not very clean.

Make it possible to specify own implementation for authorization.

Also

I saw similar issue for WebClient.
https://github.com/OpenAPITools/openapi-generator/issues/874

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the generated Java okhttp-gson ApiClient constructor and inspect how it creates the OkHttpClient and handles authentication. Done means generated clients can reuse a supplied client and support custom authorization while preserving the existing default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.