forked from loafle/openapi-generator-original
[kotlin][client] add support for okhttp requests with empty body (#10369)
* [kotlin][client] add support for okhttp requests with empty body * [kotlin][client] add support for okhttp requests with empty body
This commit is contained in:
@@ -14,6 +14,7 @@ import okhttp3.MultipartBody
|
||||
import okhttp3.Call
|
||||
import okhttp3.Callback
|
||||
import okhttp3.Response
|
||||
import okhttp3.internal.EMPTY_REQUEST
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
@@ -103,9 +104,16 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == JsonMediaType -> {
|
||||
if (content == null) {
|
||||
EMPTY_REQUEST
|
||||
} else {
|
||||
Serializer.moshi.adapter(T::class.java).toJson(content)
|
||||
.toRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
}
|
||||
}
|
||||
mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
|
||||
// TODO: this should be extended with other serializers
|
||||
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
|
||||
|
||||
Reference in New Issue
Block a user