Skip to content

Commit a67e07e

Browse files
authored
Stop using internal variable from okhttp3 (#17458)
1 parent 5eab3ce commit a67e07e

24 files changed

Lines changed: 71 additions & 23 deletions

File tree

  • modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure
  • samples/client
    • others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure
    • petstore
      • kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin/src/main/kotlin/org/openapitools/client/infrastructure

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ import okhttp3.Response
3535
{{#jvm-okhttp3}}
3636
import okhttp3.internal.Util.EMPTY_REQUEST
3737
{{/jvm-okhttp3}}
38-
{{#jvm-okhttp4}}
39-
import okhttp3.internal.EMPTY_REQUEST
40-
{{/jvm-okhttp4}}
4138
import java.io.BufferedWriter
4239
import java.io.File
4340
import java.io.FileWriter
@@ -77,6 +74,10 @@ import com.fasterxml.jackson.core.type.TypeReference
7774
import com.squareup.moshi.adapter
7875
{{/moshi}}
7976

77+
{{#jvm-okhttp4}}
78+
{{#nonPublicApi}}internal {{/nonPublicApi}} val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
79+
{{/jvm-okhttp4}}
80+
8081
{{#nonPublicApi}}internal {{/nonPublicApi}}open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
8182
{{#nonPublicApi}}internal {{/nonPublicApi}}companion object {
8283
protected const val ContentType = "Content-Type"
@@ -411,6 +412,7 @@ import com.squareup.moshi.adapter
411412
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
412413

413414
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
415+
@Suppress("UNNECESSARY_SAFE_CALL")
414416
return when {
415417
response.isRedirect -> Redirection(
416418
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},

samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import java.time.OffsetTime
2626
import java.util.Locale
2727
import com.squareup.moshi.adapter
2828

29+
2930
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3031
companion object {
3132
protected const val ContentType = "Content-Type"
@@ -198,6 +199,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
198199
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
199200

200201
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
202+
@Suppress("UNNECESSARY_SAFE_CALL")
201203
return when {
202204
response.isRedirect -> Redirection(
203205
response.code(),

samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import java.time.OffsetTime
2626
import java.util.Locale
2727
import com.squareup.moshi.adapter
2828

29+
2930
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3031
companion object {
3132
protected const val ContentType = "Content-Type"
@@ -198,6 +199,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
198199
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
199200

200201
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
202+
@Suppress("UNNECESSARY_SAFE_CALL")
201203
return when {
202204
response.isRedirect -> Redirection(
203205
response.code(),

samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.squareup.moshi.adapter
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -200,6 +201,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
200201
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
201202

202203
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
204+
@Suppress("UNNECESSARY_SAFE_CALL")
203205
return when {
204206
response.isRedirect -> Redirection(
205207
response.code,

samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import okhttp3.MultipartBody
1515
import okhttp3.Call
1616
import okhttp3.Callback
1717
import okhttp3.Response
18-
import okhttp3.internal.EMPTY_REQUEST
1918
import java.io.BufferedWriter
2019
import java.io.File
2120
import java.io.FileWriter
@@ -29,6 +28,8 @@ import java.time.OffsetTime
2928
import java.util.Locale
3029
import com.google.gson.reflect.TypeToken
3130

31+
val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody()
32+
3233
open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) {
3334
companion object {
3435
protected const val ContentType = "Content-Type"
@@ -218,6 +219,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
218219
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US)
219220

220221
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
222+
@Suppress("UNNECESSARY_SAFE_CALL")
221223
return when {
222224
response.isRedirect -> Redirection(
223225
response.code,

0 commit comments

Comments
 (0)