From 7d1e9997d006a215e3c0bd275b6f06253bd24bb3 Mon Sep 17 00:00:00 2001 From: roelwuytens-androme <140632264+roelwuytens-androme@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:18:51 +0200 Subject: [PATCH] [Kotlin] Allow other content-types when only interested in status-code / Unit (#19801) * Allow Unit response * Updating samples * Improve comment for Unit shortcut --- .../jvm-okhttp/infrastructure/ApiClient.kt.mustache | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- .../org/openapitools/client/infrastructure/ApiClient.kt | 7 +++++-- 21 files changed, 105 insertions(+), 42 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 8aabf649f883..606b70f1fa8a 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -167,8 +167,11 @@ import com.squareup.moshi.adapter val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2e3b0b4e0f76..18243f43238e 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e6a9896593e8..1d0b545aa6b2 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index aa1ce67cfcb7..fcc902c1d558 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -126,8 +126,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e63708077704..c419e4b0de2d 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -127,8 +127,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bddc06185e07..2c84a6bf23ac 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 1a8f49006069..96cab6d6d5d5 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c3d43ff809c4..fe3124d35eb0 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f381dee978ea..934673c9da9f 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition") diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c6d72a4d175f..74b362833cc9 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val body = response.body if(body == null) { return null - } - if (T::class.java == File::class.java) { + } else if (T::class.java == Unit::class.java) { + // No need to parse the body when we're not interested in the body + // Useful when API is returning other Content-Type + return null + } else if (T::class.java == File::class.java) { // return tempFile val contentDisposition = response.header("Content-Disposition")