forked from loafle/openapi-generator-original
[kotlin-client] Allowing vendor types for json (#10758)
* Using the first serializable 'consumes' mediaType Using all deserializable 'produces' mediaTypes Matching json vendor types as json * updating the generated samples
This commit is contained in:
@@ -100,7 +100,8 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet",
|
||||
@@ -170,7 +171,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
@@ -246,6 +247,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
put("tags", toMultiValue(tags.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -319,6 +321,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
}
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -387,6 +390,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -453,7 +457,8 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/pet",
|
||||
@@ -525,7 +530,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = mapOf("name" to name, "status" to status)
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded")
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
@@ -599,6 +604,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = mapOf("additionalMetadata" to additionalMetadata, "file" to file)
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "multipart/form-data")
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
|
||||
@@ -99,7 +99,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
@@ -164,6 +164,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -232,6 +233,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -300,6 +302,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
|
||||
@@ -99,7 +99,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user",
|
||||
@@ -165,7 +165,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithArray",
|
||||
@@ -231,7 +231,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithList",
|
||||
@@ -297,7 +297,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
@@ -365,6 +365,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -440,6 +441,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
put("password", listOf(password.toString()))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
@@ -503,7 +505,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/logout",
|
||||
@@ -572,7 +574,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
|
||||
@@ -106,7 +106,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> {
|
||||
mediaType.startsWith("application/") && mediaType.endsWith("json") ->
|
||||
if (content == null) {
|
||||
EMPTY_REQUEST
|
||||
} else {
|
||||
@@ -115,7 +115,6 @@ open class ApiClient(val baseUrl: String) {
|
||||
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.")
|
||||
@@ -144,8 +143,9 @@ open class ApiClient(val baseUrl: String) {
|
||||
out.close()
|
||||
return f as T
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter<T>().fromJson(bodyContent)
|
||||
return when {
|
||||
mediaType==null || (mediaType.startsWith("application/") && mediaType.endsWith("json")) ->
|
||||
Serializer.moshi.adapter<T>().fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
@@ -192,11 +192,11 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
if(headers[ContentType].isNullOrEmpty()) {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
if(headers[Accept].isNullOrEmpty()) {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user