Skip to content

Commit 2f16218

Browse files
committed
Adapt textual content body to support primitive types.
1 parent 0f36a83 commit 2f16218

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,15 @@ import com.squareup.moshi.adapter
323323
.toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull())
324324
}
325325
mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.")
326-
mediaType == TEXT_MEDIA_TYPE && content is String ->
327-
content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull())
326+
mediaType == TEXT_MEDIA_TYPE -> {
327+
val textualContent = when {
328+
content is CharSequence -> content.toString()
329+
content is Number -> content.toString()
330+
content is Boolean -> content.toString()
331+
else -> throw UnsupportedOperationException("requestBody currently only supports text body containing primitive types: characters, numbers, or booleans.")
332+
}
333+
textualContent.toRequestBody(mediaType.toMediaTypeOrNull())
334+
}
328335
// TODO: this should be extended with other serializers
329336
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.")
330337
}

0 commit comments

Comments
 (0)