forked from loafle/openapi-generator-original
[Kotlin][retrofit2] replace okhttpclient with callfactory (#9451)
* [Kotlin][Retrofit][#9448] Replace OkHttpClient parameter with Call.Factory. * [Kotlin][Retrofit][#9448] Update sample project.
This commit is contained in:
parent
763f65f293
commit
1b6fd2dd7a
@ -21,6 +21,7 @@ import {{packageName}}.auth.HttpBearerAuth
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
import okhttp3.Call
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
@ -56,7 +57,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
private var baseUrl: String = defaultBasePath,
|
||||
private val okHttpClientBuilder: OkHttpClient.Builder? = null{{^kotlinx_serialization}},
|
||||
private val serializerBuilder: {{#gson}}Gson{{/gson}}{{#moshi}}Moshi.{{/moshi}}Builder = Serializer.{{#gson}}gson{{/gson}}{{#moshi}}moshi{{/moshi}}Builder{{/kotlinx_serialization}},
|
||||
private val okHttpClient : OkHttpClient? = null,
|
||||
private val callFactory : Call.Factory? = null,
|
||||
private val converterFactory: Converter.Factory? = null,
|
||||
) {
|
||||
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
||||
@ -303,8 +304,8 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
}
|
||||
|
||||
fun <S> createService(serviceClass: Class<S>): S {
|
||||
val usedClient = this.okHttpClient ?: clientBuilder.build()
|
||||
return retrofitBuilder.client(usedClient).build().create(serviceClass)
|
||||
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
||||
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
||||
}
|
||||
|
||||
private fun normalizeBaseUrl() {
|
||||
|
@ -7,6 +7,7 @@ import org.openapitools.client.auth.OAuth
|
||||
import org.openapitools.client.auth.OAuth.AccessTokenListener
|
||||
import org.openapitools.client.auth.OAuthFlow
|
||||
|
||||
import okhttp3.Call
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
@ -21,7 +22,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
class ApiClient(
|
||||
private var baseUrl: String = defaultBasePath,
|
||||
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
|
||||
private val okHttpClient : OkHttpClient? = null,
|
||||
private val callFactory : Call.Factory? = null,
|
||||
private val converterFactory: Converter.Factory? = null,
|
||||
) {
|
||||
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
||||
@ -180,8 +181,8 @@ class ApiClient(
|
||||
}
|
||||
|
||||
fun <S> createService(serviceClass: Class<S>): S {
|
||||
val usedClient = this.okHttpClient ?: clientBuilder.build()
|
||||
return retrofitBuilder.client(usedClient).build().create(serviceClass)
|
||||
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
||||
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
||||
}
|
||||
|
||||
private fun normalizeBaseUrl() {
|
||||
|
@ -7,6 +7,7 @@ import org.openapitools.client.auth.OAuth
|
||||
import org.openapitools.client.auth.OAuth.AccessTokenListener
|
||||
import org.openapitools.client.auth.OAuthFlow
|
||||
|
||||
import okhttp3.Call
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
@ -22,7 +23,7 @@ class ApiClient(
|
||||
private var baseUrl: String = defaultBasePath,
|
||||
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
|
||||
private val serializerBuilder: Moshi.Builder = Serializer.moshiBuilder,
|
||||
private val okHttpClient : OkHttpClient? = null,
|
||||
private val callFactory : Call.Factory? = null,
|
||||
private val converterFactory: Converter.Factory? = null,
|
||||
) {
|
||||
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
||||
@ -183,8 +184,8 @@ class ApiClient(
|
||||
}
|
||||
|
||||
fun <S> createService(serviceClass: Class<S>): S {
|
||||
val usedClient = this.okHttpClient ?: clientBuilder.build()
|
||||
return retrofitBuilder.client(usedClient).build().create(serviceClass)
|
||||
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
||||
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
||||
}
|
||||
|
||||
private fun normalizeBaseUrl() {
|
||||
|
@ -7,6 +7,7 @@ import org.openapitools.client.auth.OAuth
|
||||
import org.openapitools.client.auth.OAuth.AccessTokenListener
|
||||
import org.openapitools.client.auth.OAuthFlow
|
||||
|
||||
import okhttp3.Call
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
@ -21,7 +22,7 @@ class ApiClient(
|
||||
private var baseUrl: String = defaultBasePath,
|
||||
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
|
||||
private val serializerBuilder: Moshi.Builder = Serializer.moshiBuilder,
|
||||
private val okHttpClient : OkHttpClient? = null,
|
||||
private val callFactory : Call.Factory? = null,
|
||||
private val converterFactory: Converter.Factory? = null,
|
||||
) {
|
||||
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
||||
@ -180,8 +181,8 @@ class ApiClient(
|
||||
}
|
||||
|
||||
fun <S> createService(serviceClass: Class<S>): S {
|
||||
val usedClient = this.okHttpClient ?: clientBuilder.build()
|
||||
return retrofitBuilder.client(usedClient).build().create(serviceClass)
|
||||
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
||||
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
||||
}
|
||||
|
||||
private fun normalizeBaseUrl() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user