diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 67f41edc715..b37294c2a9d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -962,7 +962,9 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { ).trim(); return "multipart/form-data".equals(mediaType) || "application/x-www-form-urlencoded".equals(mediaType) - || (mediaType.startsWith("application/") && (mediaType.endsWith("json") || mediaType.endsWith("octet-stream"))); + || (mediaType.startsWith("application/") && mediaType.endsWith("json")) + || "application/octet-stream".equals(mediaType) + || "text/plain".equals(mediaType); }; operation.consumes = operation.consumes == null ? null : operation.consumes.stream() .filter(isSerializable) 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 2b8dcc1c5b6..bc0027e7405 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 @@ -70,6 +70,7 @@ import com.squareup.moshi.adapter protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKey: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKeyPrefix: MutableMap = mutableMapOf() @@ -209,10 +210,10 @@ import com.squareup.moshi.adapter .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } {{#moshi}} @@ -298,7 +299,8 @@ import com.squareup.moshi.adapter }}{{#kotlinx_serialization}}Serializer.kotlinxSerializationJson.decodeFromString(bodyContent){{/kotlinx_serialization}} } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 158ee6350bd..b76315bd9e8 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 @@ -41,6 +41,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" public val apiKey: MutableMap = mutableMapOf() public val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 42330f0a049..1911b1d4788 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { @@ -242,7 +243,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 e72665e5548..44095e73f25 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { @@ -242,7 +243,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.jacksonObjectMapper.readValue(bodyContent, object: TypeReference() {}) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 502a01ba2b9..70539f9c852 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 @@ -43,6 +43,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -171,10 +172,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { @@ -248,7 +249,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.kotlinxSerializationJson.decodeFromString(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 e4c296b20e9..5a8f81566cf 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 @@ -44,6 +44,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -172,10 +173,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { @@ -245,7 +246,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 92580a974dd..e59fa0b5a48 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 87f80e81ab0..ad481e08ba5 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 @@ -41,6 +41,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 3ec87d33987..83cf91d8928 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 238f6dcca90..09a59bf60d7 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 @@ -42,6 +42,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -170,10 +171,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.kotlinxSerializationJson.decodeFromString(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte 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 b1cf2c6828c..0867fa0c317 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 @@ -41,6 +41,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" protected const val XmlMediaType: String = "application/xml" protected const val OctetMediaType: String = "application/octet-stream" + protected const val TextMediaType: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -169,10 +170,10 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == OctetMediaType && content is ByteArray -> - content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) + mediaType == TextMediaType && content is String -> + content.toRequestBody(TextMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) @@ -243,7 +244,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie Serializer.moshi.adapter().fromJson(bodyContent) } mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + mediaType == TextMediaType -> body.string() as? T + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } }