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 0a0b7fc303f5..90bb67fba34d 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 @@ -323,8 +323,15 @@ import com.squareup.moshi.adapter .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index b8085ef31f75..d19798f76420 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c78ab5e0d9ef..be634822add2 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index b6fabcf91636..1ccdd316091b 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c7334e173bcd..57e65c505bf9 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cccc180e9524..68c0a8f0d5b9 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -273,8 +273,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c78ab5e0d9ef..be634822add2 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c78ab5e0d9ef..be634822add2 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index de25fbf36665..fa958cc71f82 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -270,8 +270,15 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 df427adfe681..1dd8eef7ca7a 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 b74ee7ab19e9..7bd1ff70d79d 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 b5cbd5bd1cb4..5e768a876c10 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 @@ -274,8 +274,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 fe635449f668..dd7ecca5e710 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 @@ -273,8 +273,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 c78ab5e0d9ef..be634822add2 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 41ca6b16533d..a318ecb5f1d3 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 @@ -270,8 +270,15 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 7322b44ff2c2..8fed2b41fc53 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 cccc180e9524..68c0a8f0d5b9 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 @@ -273,8 +273,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } 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 879f5998dfcd..cd4456aa818e 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 @@ -270,8 +270,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TEXT_MEDIA_TYPE && content is String -> - content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) + mediaType == TEXT_MEDIA_TYPE -> { + val textualContent = when (content) { + is Char, is CharSequence -> content.toString() + is Number -> content.toString() + is Boolean -> content.toString() + else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.") + } + textualContent.toRequestBody(mediaType.toMediaTypeOrNull()) + } // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") }