[Kotlin][Retrofit] Change OkHttpClient parameter to Call.Factory
Created by: shanselm-ergon
With OpenApi version 5 a new constructor parameter got added to pass an OkHttpClient
to the ApiClient
([#6855]). We thought this is good enough for us, but now we run into some problems with this approach. The parameter should be changed to a Call.Factory
instead.
- Smaller interface
- Only the Call.Factory is used (see
retrofitBuilder.client(usedClient)
, this just sets theCall.Factory
) - It is more like it was before version 5 of OpenApi (the exposed
adapterBuilder
had acallFactory
method) - In our use case, we need to replace the underlying http-client during runtime. If we only have to pass the
Call.Factory
we can easily do this, but if we have to pass the client itself we can't achieve this properly.
Describe the solution you'd like
Change the parameter from OkHttpClient
to Call.Factory
. Each OkHttpClient
is also a Call.Factory
, so minimal effort to adopt this change.
Describe alternatives you've considered
With the knowledge that only the Call.Factory
interface is used by the ApiClient
we could also create our own version of a OkHttpClient
and only overwrite the newCall(request)
method. But this is based on internal knowledge, which should not be part of the ApiClient
API.
I will create a pull request suggestion for this improvement.