Skip to content

Commit

Permalink
[Kotlin][Retrofit][OpenAPITools#9448] Update sample project.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanselm-ergon committed May 11, 2021
1 parent 7a1141b commit 0f595c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>()
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>()
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>()
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0f595c6

Please sign in to comment.