OkHttpClient - replacing static client usage with client Injection #12444 (#12448)

Co-authored-by: Grigory Tihonov <grigory.tihonov@lamoda.ru>
This commit is contained in:
CodeR
2022-05-24 16:51:47 +04:00
committed by GitHub
parent de8decc9f5
commit 73b0762f36
64 changed files with 128 additions and 84 deletions

View File

@@ -21,6 +21,7 @@
package org.openapitools.client.apis
import java.io.IOException
import okhttp3.OkHttpClient
import org.openapitools.client.models.ModelWithEnumPropertyHavingDefault
@@ -40,7 +41,7 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue
class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = ApiClient.defaultClient) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {

View File

@@ -29,7 +29,7 @@ import java.time.OffsetTime
import java.util.Locale
import com.squareup.moshi.adapter
open class ApiClient(val baseUrl: String) {
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
companion object {
protected const val ContentType = "Content-Type"
protected const val Accept = "Accept"
@@ -47,7 +47,7 @@ open class ApiClient(val baseUrl: String) {
const val baseUrlKey = "org.openapitools.client.baseUrl"
@JvmStatic
val client: OkHttpClient by lazy {
val defaultClient: OkHttpClient by lazy {
builder.build()
}