From a3322fbf7e51926fa01c75044c19d528e3fc770b Mon Sep 17 00:00:00 2001 From: Yukio Ejiri Date: Fri, 6 Apr 2018 16:27:39 +0900 Subject: [PATCH] [kotlin] Add OkHttpClient.Builder to ApiClient. (#7907) --- .../kotlin-client/infrastructure/ApiClient.kt.mustache | 7 ++++++- .../kotlin/io/swagger/client/infrastructure/ApiClient.kt | 7 ++++++- .../kotlin/io/swagger/client/infrastructure/ApiClient.kt | 7 ++++++- .../kotlin/io/swagger/client/infrastructure/ApiClient.kt | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache index e46256a35673..934cf63524d0 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache @@ -12,7 +12,12 @@ open class ApiClient(val baseUrl: String) { protected val XmlMediaType = "application/xml" @JvmStatic - val client : OkHttpClient = OkHttpClient() + val client by lazy { + builder.build() + } + + @JvmStatic + val builder: OkHttpClient.Builder = OkHttpClient.Builder() @JvmStatic var defaultHeaders: Map by ApplicationDelegates.setOnce(mapOf(ContentType to JsonMediaType, Accept to JsonMediaType)) diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index eb13afafce65..7e3a11664bd0 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -12,7 +12,12 @@ open class ApiClient(val baseUrl: String) { protected val XmlMediaType = "application/xml" @JvmStatic - val client : OkHttpClient = OkHttpClient() + val client by lazy { + builder.build() + } + + @JvmStatic + val builder: OkHttpClient.Builder = OkHttpClient.Builder() @JvmStatic var defaultHeaders: Map by ApplicationDelegates.setOnce(mapOf(ContentType to JsonMediaType, Accept to JsonMediaType)) diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index eb13afafce65..7e3a11664bd0 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -12,7 +12,12 @@ open class ApiClient(val baseUrl: String) { protected val XmlMediaType = "application/xml" @JvmStatic - val client : OkHttpClient = OkHttpClient() + val client by lazy { + builder.build() + } + + @JvmStatic + val builder: OkHttpClient.Builder = OkHttpClient.Builder() @JvmStatic var defaultHeaders: Map by ApplicationDelegates.setOnce(mapOf(ContentType to JsonMediaType, Accept to JsonMediaType)) diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index eb13afafce65..7e3a11664bd0 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -12,7 +12,12 @@ open class ApiClient(val baseUrl: String) { protected val XmlMediaType = "application/xml" @JvmStatic - val client : OkHttpClient = OkHttpClient() + val client by lazy { + builder.build() + } + + @JvmStatic + val builder: OkHttpClient.Builder = OkHttpClient.Builder() @JvmStatic var defaultHeaders: Map by ApplicationDelegates.setOnce(mapOf(ContentType to JsonMediaType, Accept to JsonMediaType))