OpenAPITools / OpenAPITools/openapi-generator
[REQ] Allow to pass OkHttpClient into ApiClient constructor
Nobody has claimed this yet.
- 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
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 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