mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-05 08:46:11 +00:00
Kotlin: Fix kotlinx_serialization code generation (#9576)
And update to Kotlin 1.5.0 and kotlinx.serialization 1.2.1. Fix nested enum annotation '@Serializable' instead of '@KSerializable' when 'kotlinx_serialization' is used. Fix missing JsonMediaType in ApiClient.kt (#9242). Add 'kotlinx_serialization' serialization library to documentation. Use explicity type in RequestConfig to keep type information for JSON serialization. Resolves #9242
This commit is contained in:
@@ -7,7 +7,7 @@ wrapper {
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.30'
|
||||
ext.kotlin_version = '1.5.0'
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo1.maven.org/maven2" }
|
||||
|
||||
@@ -47,7 +47,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableConfig = addPetRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Pet, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -72,20 +72,18 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun addPetRequestConfig(body: Pet) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun addPetRequestConfig(body: Pet) : RequestConfig<Pet> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +100,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Unit, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -128,21 +126,19 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param apiKey (optional)
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +156,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableConfig = findPetsByTagsRequestConfig(tags = tags)
|
||||
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
val localVarResponse = request<Unit, kotlin.collections.List<Pet>>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -186,23 +182,21 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @return RequestConfig
|
||||
*/
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTagsRequestConfig(tags: kotlin.collections.List<kotlin.String>) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun findPetsByTagsRequestConfig(tags: kotlin.collections.List<kotlin.String>) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("tags", toMultiValue(tags.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +213,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun getAllPets(lastUpdated: java.time.OffsetDateTime?) : kotlin.collections.List<Pet> {
|
||||
val localVariableConfig = getAllPetsRequestConfig(lastUpdated = lastUpdated)
|
||||
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
val localVarResponse = request<Unit, kotlin.collections.List<Pet>>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -244,8 +238,8 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param lastUpdated When this endpoint was hit last to help indentify if the client already has the latest copy. (optional)
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getAllPetsRequestConfig(lastUpdated: java.time.OffsetDateTime?) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getAllPetsRequestConfig(lastUpdated: java.time.OffsetDateTime?) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
if (lastUpdated != null) {
|
||||
@@ -253,16 +247,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
}
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/getAll",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +271,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableConfig = getPetByIdRequestConfig(petId = petId)
|
||||
|
||||
val localVarResponse = request<Pet>(
|
||||
val localVarResponse = request<Unit, Pet>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -304,20 +296,18 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param petId ID of pet to return
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +323,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableConfig = updatePetRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Pet, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -358,20 +348,18 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun updatePetRequestConfig(body: Pet) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun updatePetRequestConfig(body: Pet) : RequestConfig<Pet> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,7 +377,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Map<String, Any?>, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -416,20 +404,18 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status)
|
||||
fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig<Map<String, Any?>> {
|
||||
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")
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -448,7 +434,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file)
|
||||
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
val localVarResponse = request<Map<String, Any?>, ApiResponse>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -475,20 +461,18 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param file file to upload (optional)
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file)
|
||||
fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig<Map<String, Any?>> {
|
||||
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")
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableConfig = deleteOrderRequestConfig(orderId = orderId)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Unit, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -71,20 +71,18 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +98,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableConfig = getInventoryRequestConfig()
|
||||
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
val localVarResponse = request<Unit, kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -124,20 +122,18 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
*
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getInventoryRequestConfig() : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getInventoryRequestConfig() : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +150,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId)
|
||||
|
||||
val localVarResponse = request<Order>(
|
||||
val localVarResponse = request<Unit, Order>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -179,20 +175,18 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +203,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableConfig = placeOrderRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Order>(
|
||||
val localVarResponse = request<Order, Order>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -234,20 +228,18 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun placeOrderRequestConfig(body: Order) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun placeOrderRequestConfig(body: Order) : RequestConfig<Order> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableConfig = createUserRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<User, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -71,20 +71,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body Created user object
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun createUserRequestConfig(body: User) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun createUserRequestConfig(body: User) : RequestConfig<User> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +98,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<kotlin.collections.List<User>, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -125,20 +123,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body List of user object
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List<User>) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List<User>) : RequestConfig<kotlin.collections.List<User>> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +150,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableConfig = createUsersWithListInputRequestConfig(body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<kotlin.collections.List<User>, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -179,20 +175,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body List of user object
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun createUsersWithListInputRequestConfig(body: kotlin.collections.List<User>) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun createUsersWithListInputRequestConfig(body: kotlin.collections.List<User>) : RequestConfig<kotlin.collections.List<User>> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +202,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableConfig = deleteUserRequestConfig(username = username)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Unit, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -233,20 +227,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param username The name that needs to be deleted
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +255,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableConfig = getUserByNameRequestConfig(username = username)
|
||||
|
||||
val localVarResponse = request<User>(
|
||||
val localVarResponse = request<Unit, User>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -288,20 +280,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +309,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableConfig = loginUserRequestConfig(username = username, password = password)
|
||||
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
val localVarResponse = request<Unit, kotlin.String>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -345,24 +335,22 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param password The password for login in clear text
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("username", listOf(username.toString()))
|
||||
put("password", listOf(password.toString()))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,7 +365,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableConfig = logoutUserRequestConfig()
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<Unit, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -401,20 +389,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
*
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun logoutUserRequestConfig() : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun logoutUserRequestConfig() : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +417,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableConfig = updateUserRequestConfig(username = username, body = body)
|
||||
|
||||
val localVarResponse = request<Any?>(
|
||||
val localVarResponse = request<User, Unit>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -457,20 +443,18 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
* @param body Updated user object
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig<User> {
|
||||
val localVariableBody = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,16 +13,17 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.net.URLConnection
|
||||
import java.util.Date
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalTime
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.OffsetTime
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
@@ -62,9 +63,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
content is File -> content.asRequestBody(mediaType.toMediaTypeOrNull())
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
@@ -137,7 +136,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
protected fun <T> updateAuthParams(requestConfig: RequestConfig<T>) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
@@ -154,7 +153,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig): ApiInfrastructureResponse<T?> {
|
||||
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
@@ -188,7 +187,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||
@@ -203,57 +202,46 @@ open class ApiClient(val baseUrl: String) {
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.getDefault())
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
return when {
|
||||
response.isRedirect -> Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isInformational -> Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isSuccessful -> Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isClientError -> ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return ServerError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
else -> ServerError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun parameterToString(value: Any?): String {
|
||||
when (value) {
|
||||
null -> {
|
||||
return ""
|
||||
}
|
||||
is Array<*> -> {
|
||||
return toMultiValue(value, "csv").toString()
|
||||
}
|
||||
is Iterable<*> -> {
|
||||
return toMultiValue(value, "csv").toString()
|
||||
}
|
||||
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime, is Date -> {
|
||||
return parseDateToQueryString<Any>(value)
|
||||
}
|
||||
else -> {
|
||||
return value.toString()
|
||||
}
|
||||
}
|
||||
protected fun parameterToString(value: Any?): String = when (value) {
|
||||
null -> ""
|
||||
is Array<*> -> toMultiValue(value, "csv").toString()
|
||||
is Iterable<*> -> toMultiValue(value, "csv").toString()
|
||||
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime, is Date ->
|
||||
parseDateToQueryString(value)
|
||||
else -> value.toString()
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||
|
||||
@@ -8,10 +8,10 @@ package org.openapitools.client.infrastructure
|
||||
* NOTE: Headers is a Map<String,String> because rfc2616 defines
|
||||
* multi-valued headers as csv-only.
|
||||
*/
|
||||
data class RequestConfig(
|
||||
data class RequestConfig<T>(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
||||
val body: kotlin.Any? = null
|
||||
val body: T? = null
|
||||
)
|
||||
Reference in New Issue
Block a user