[kotlin-client] New generator: kotlin-jvm-spring-restclient (#17366)

* Created kotlin jvm spring restclient

* Fixed kotlin jvm-spring-restclient

* Fixed earlier problems

* Fixed earlier problems

* Updated kotlin.md
This commit is contained in:
Stefan Koppier
2023-12-11 05:49:36 +01:00
committed by GitHub
parent 9eb5882f94
commit 7f05c1f41d
43 changed files with 3163 additions and 6 deletions

View File

@@ -0,0 +1,312 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.apis
import com.fasterxml.jackson.annotation.JsonProperty
import org.springframework.web.client.RestClient
import org.springframework.web.client.RestClientResponseException
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.http.ResponseEntity
import org.springframework.http.MediaType
import org.openapitools.client.models.ModelApiResponse
import org.openapitools.client.models.Pet
import org.openapitools.client.infrastructure.*
class PetApi(client: RestClient) : ApiClient(client) {
constructor(baseUrl: String) : this(RestClient.builder()
.baseUrl(baseUrl)
.messageConverters { it.add(MappingJackson2HttpMessageConverter()) }
.build()
)
@Throws(RestClientResponseException::class)
fun addPet(pet: Pet): Pet {
return addPetWithHttpInfo(pet = pet)
.body!!
}
@Throws(RestClientResponseException::class)
fun addPetWithHttpInfo(pet: Pet): ResponseEntity<Pet> {
val localVariableConfig = addPetRequestConfig(pet = pet)
return request<Pet, Pet>(
localVariableConfig
)
}
fun addPetRequestConfig(pet: Pet) : RequestConfig<Pet> {
val localVariableBody = pet
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
localVariableHeaders["Content-Type"] = "application/xml"
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/pet",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit {
return deletePetWithHttpInfo(petId = petId, apiKey = apiKey)
.body!!
}
@Throws(RestClientResponseException::class)
fun deletePetWithHttpInfo(petId: kotlin.Long, apiKey: kotlin.String?): ResponseEntity<Unit> {
val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey)
return request<Unit, Unit>(
localVariableConfig
)
}
fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
return RequestConfig(
method = RequestMethod.DELETE,
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
/**
* enum for parameter status
*/
enum class StatusFindPetsByStatus(val value: kotlin.String) {
@JsonProperty(value = "available") available("available"),
@JsonProperty(value = "pending") pending("pending"),
@JsonProperty(value = "sold") sold("sold"),
}
@Throws(RestClientResponseException::class)
fun findPetsByStatus(status: kotlin.collections.List<StatusFindPetsByStatus>): kotlin.collections.List<Pet> {
return findPetsByStatusWithHttpInfo(status = status)
.body!!
}
@Throws(RestClientResponseException::class)
fun findPetsByStatusWithHttpInfo(status: kotlin.collections.List<StatusFindPetsByStatus>): ResponseEntity<kotlin.collections.List<Pet>> {
val localVariableConfig = findPetsByStatusRequestConfig(status = status)
return request<Unit, kotlin.collections.List<Pet>>(
localVariableConfig
)
}
fun findPetsByStatusRequestConfig(status: kotlin.collections.List<StatusFindPetsByStatus>) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
.apply {
put("status", toMultiValue(status.toList(), "csv"))
}
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/pet/findByStatus",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
@Deprecated(message = "This operation is deprecated.")
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): kotlin.collections.List<Pet> {
return findPetsByTagsWithHttpInfo(tags = tags)
.body!!
}
@Throws(RestClientResponseException::class)
@Deprecated(message = "This operation is deprecated.")
fun findPetsByTagsWithHttpInfo(tags: kotlin.collections.List<kotlin.String>): ResponseEntity<kotlin.collections.List<Pet>> {
val localVariableConfig = findPetsByTagsRequestConfig(tags = tags)
return request<Unit, kotlin.collections.List<Pet>>(
localVariableConfig
)
}
@Deprecated(message = "This operation is deprecated.")
fun findPetsByTagsRequestConfig(tags: kotlin.collections.List<kotlin.String>) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
.apply {
put("tags", toMultiValue(tags.toList(), "csv"))
}
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/pet/findByTags",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun getPetById(petId: kotlin.Long): Pet {
return getPetByIdWithHttpInfo(petId = petId)
.body!!
}
@Throws(RestClientResponseException::class)
fun getPetByIdWithHttpInfo(petId: kotlin.Long): ResponseEntity<Pet> {
val localVariableConfig = getPetByIdRequestConfig(petId = petId)
return request<Unit, Pet>(
localVariableConfig
)
}
fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun updatePet(pet: Pet): Pet {
return updatePetWithHttpInfo(pet = pet)
.body!!
}
@Throws(RestClientResponseException::class)
fun updatePetWithHttpInfo(pet: Pet): ResponseEntity<Pet> {
val localVariableConfig = updatePetRequestConfig(pet = pet)
return request<Pet, Pet>(
localVariableConfig
)
}
fun updatePetRequestConfig(pet: Pet) : RequestConfig<Pet> {
val localVariableBody = pet
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
localVariableHeaders["Content-Type"] = "application/xml"
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.PUT,
path = "/pet",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit {
return updatePetWithFormWithHttpInfo(petId = petId, name = name, status = status)
.body!!
}
@Throws(RestClientResponseException::class)
fun updatePetWithFormWithHttpInfo(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): ResponseEntity<Unit> {
val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status)
return request<Map<String, PartConfig<*>>, Unit>(
localVariableConfig
)
}
fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig<Map<String, PartConfig<*>>> {
val localVariableBody = mapOf(
"name" to PartConfig(body = name, headers = mutableMapOf()),
"status" to PartConfig(body = status, headers = mutableMapOf()),)
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded")
return RequestConfig(
method = RequestMethod.POST,
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?): ModelApiResponse {
return uploadFileWithHttpInfo(petId = petId, additionalMetadata = additionalMetadata, file = file)
.body!!
}
@Throws(RestClientResponseException::class)
fun uploadFileWithHttpInfo(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?): ResponseEntity<ModelApiResponse> {
val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file)
return request<Map<String, PartConfig<*>>, ModelApiResponse>(
localVariableConfig
)
}
fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig<Map<String, PartConfig<*>>> {
val localVariableBody = mapOf(
"additionalMetadata" to PartConfig(body = additionalMetadata, headers = mutableMapOf()),
"file" to PartConfig(body = file, headers = mutableMapOf()),)
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "multipart/form-data")
localVariableHeaders["Accept"] = "application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
}

View File

@@ -0,0 +1,162 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.apis
import com.fasterxml.jackson.annotation.JsonProperty
import org.springframework.web.client.RestClient
import org.springframework.web.client.RestClientResponseException
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.http.ResponseEntity
import org.springframework.http.MediaType
import org.openapitools.client.models.Order
import org.openapitools.client.infrastructure.*
class StoreApi(client: RestClient) : ApiClient(client) {
constructor(baseUrl: String) : this(RestClient.builder()
.baseUrl(baseUrl)
.messageConverters { it.add(MappingJackson2HttpMessageConverter()) }
.build()
)
@Throws(RestClientResponseException::class)
fun deleteOrder(orderId: kotlin.String): Unit {
return deleteOrderWithHttpInfo(orderId = orderId)
.body!!
}
@Throws(RestClientResponseException::class)
fun deleteOrderWithHttpInfo(orderId: kotlin.String): ResponseEntity<Unit> {
val localVariableConfig = deleteOrderRequestConfig(orderId = orderId)
return request<Unit, Unit>(
localVariableConfig
)
}
fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
return RequestConfig(
method = RequestMethod.DELETE,
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = false,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun getInventory(): kotlin.collections.Map<kotlin.String, kotlin.Int> {
return getInventoryWithHttpInfo()
.body!!
}
@Throws(RestClientResponseException::class)
fun getInventoryWithHttpInfo(): ResponseEntity<kotlin.collections.Map<kotlin.String, kotlin.Int>> {
val localVariableConfig = getInventoryRequestConfig()
return request<Unit, kotlin.collections.Map<kotlin.String, kotlin.Int>>(
localVariableConfig
)
}
fun getInventoryRequestConfig() : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/store/inventory",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun getOrderById(orderId: kotlin.Long): Order {
return getOrderByIdWithHttpInfo(orderId = orderId)
.body!!
}
@Throws(RestClientResponseException::class)
fun getOrderByIdWithHttpInfo(orderId: kotlin.Long): ResponseEntity<Order> {
val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId)
return request<Unit, Order>(
localVariableConfig
)
}
fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = false,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun placeOrder(order: Order): Order {
return placeOrderWithHttpInfo(order = order)
.body!!
}
@Throws(RestClientResponseException::class)
fun placeOrderWithHttpInfo(order: Order): ResponseEntity<Order> {
val localVariableConfig = placeOrderRequestConfig(order = order)
return request<Order, Order>(
localVariableConfig
)
}
fun placeOrderRequestConfig(order: Order) : RequestConfig<Order> {
val localVariableBody = order
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/store/order",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = false,
body = localVariableBody
)
}
}

View File

@@ -0,0 +1,288 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.apis
import com.fasterxml.jackson.annotation.JsonProperty
import org.springframework.web.client.RestClient
import org.springframework.web.client.RestClientResponseException
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.http.ResponseEntity
import org.springframework.http.MediaType
import org.openapitools.client.models.User
import org.openapitools.client.infrastructure.*
class UserApi(client: RestClient) : ApiClient(client) {
constructor(baseUrl: String) : this(RestClient.builder()
.baseUrl(baseUrl)
.messageConverters { it.add(MappingJackson2HttpMessageConverter()) }
.build()
)
@Throws(RestClientResponseException::class)
fun createUser(user: User): Unit {
return createUserWithHttpInfo(user = user)
.body!!
}
@Throws(RestClientResponseException::class)
fun createUserWithHttpInfo(user: User): ResponseEntity<Unit> {
val localVariableConfig = createUserRequestConfig(user = user)
return request<User, Unit>(
localVariableConfig
)
}
fun createUserRequestConfig(user: User) : RequestConfig<User> {
val localVariableBody = user
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/user",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun createUsersWithArrayInput(user: kotlin.collections.List<User>): Unit {
return createUsersWithArrayInputWithHttpInfo(user = user)
.body!!
}
@Throws(RestClientResponseException::class)
fun createUsersWithArrayInputWithHttpInfo(user: kotlin.collections.List<User>): ResponseEntity<Unit> {
val localVariableConfig = createUsersWithArrayInputRequestConfig(user = user)
return request<kotlin.collections.List<User>, Unit>(
localVariableConfig
)
}
fun createUsersWithArrayInputRequestConfig(user: kotlin.collections.List<User>) : RequestConfig<kotlin.collections.List<User>> {
val localVariableBody = user
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/user/createWithArray",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun createUsersWithListInput(user: kotlin.collections.List<User>): Unit {
return createUsersWithListInputWithHttpInfo(user = user)
.body!!
}
@Throws(RestClientResponseException::class)
fun createUsersWithListInputWithHttpInfo(user: kotlin.collections.List<User>): ResponseEntity<Unit> {
val localVariableConfig = createUsersWithListInputRequestConfig(user = user)
return request<kotlin.collections.List<User>, Unit>(
localVariableConfig
)
}
fun createUsersWithListInputRequestConfig(user: kotlin.collections.List<User>) : RequestConfig<kotlin.collections.List<User>> {
val localVariableBody = user
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
return RequestConfig(
method = RequestMethod.POST,
path = "/user/createWithList",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun deleteUser(username: kotlin.String): Unit {
return deleteUserWithHttpInfo(username = username)
.body!!
}
@Throws(RestClientResponseException::class)
fun deleteUserWithHttpInfo(username: kotlin.String): ResponseEntity<Unit> {
val localVariableConfig = deleteUserRequestConfig(username = username)
return request<Unit, Unit>(
localVariableConfig
)
}
fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
return RequestConfig(
method = RequestMethod.DELETE,
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun getUserByName(username: kotlin.String): User {
return getUserByNameWithHttpInfo(username = username)
.body!!
}
@Throws(RestClientResponseException::class)
fun getUserByNameWithHttpInfo(username: kotlin.String): ResponseEntity<User> {
val localVariableConfig = getUserByNameRequestConfig(username = username)
return request<Unit, User>(
localVariableConfig
)
}
fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = false,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String {
return loginUserWithHttpInfo(username = username, password = password)
.body!!
}
@Throws(RestClientResponseException::class)
fun loginUserWithHttpInfo(username: kotlin.String, password: kotlin.String): ResponseEntity<kotlin.String> {
val localVariableConfig = loginUserRequestConfig(username = username, password = password)
return request<Unit, kotlin.String>(
localVariableConfig
)
}
fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
.apply {
put("username", listOf(username.toString()))
put("password", listOf(password.toString()))
}
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/xml, application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/user/login",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = false,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun logoutUser(): Unit {
return logoutUserWithHttpInfo()
.body!!
}
@Throws(RestClientResponseException::class)
fun logoutUserWithHttpInfo(): ResponseEntity<Unit> {
val localVariableConfig = logoutUserRequestConfig()
return request<Unit, Unit>(
localVariableConfig
)
}
fun logoutUserRequestConfig() : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
return RequestConfig(
method = RequestMethod.GET,
path = "/user/logout",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
@Throws(RestClientResponseException::class)
fun updateUser(username: kotlin.String, user: User): Unit {
return updateUserWithHttpInfo(username = username, user = user)
.body!!
}
@Throws(RestClientResponseException::class)
fun updateUserWithHttpInfo(username: kotlin.String, user: User): ResponseEntity<Unit> {
val localVariableConfig = updateUserRequestConfig(username = username, user = user)
return request<User, Unit>(
localVariableConfig
)
}
fun updateUserRequestConfig(username: kotlin.String, user: User) : RequestConfig<User> {
val localVariableBody = user
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Content-Type"] = "application/json"
return RequestConfig(
method = RequestMethod.PUT,
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
body = localVariableBody
)
}
}

View File

@@ -0,0 +1,23 @@
package org.openapitools.client.infrastructure
typealias MultiValueMap = MutableMap<String,List<String>>
fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
"csv" -> ","
"tsv" -> "\t"
"pipe" -> "|"
"space" -> " "
else -> ""
}
val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
= toMultiValue(items.asIterable(), collectionFormat, map)
fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
return when(collectionFormat) {
"multi" -> items.map(map)
else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
}
}

View File

@@ -0,0 +1,65 @@
package org.openapitools.client.infrastructure;
import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.web.util.UriUtils
import org.springframework.web.client.RestClient
import org.springframework.http.ResponseEntity
open class ApiClient(protected val client: RestClient) {
protected inline fun <reified I : Any, reified T: Any?> request(requestConfig: RequestConfig<I>): ResponseEntity<T> {
return prepare(defaults(requestConfig))
.retrieve()
.toEntity(object : ParameterizedTypeReference<T>() {})
}
protected fun <I : Any> prepare(requestConfig: RequestConfig<I>) =
client.method(requestConfig)
.uri(requestConfig)
.headers(requestConfig)
.nullableBody(requestConfig)
protected fun <I> defaults(requestConfig: RequestConfig<I>) =
requestConfig.apply {
if (body != null && headers[HttpHeaders.CONTENT_TYPE].isNullOrEmpty()) {
headers[HttpHeaders.CONTENT_TYPE] = MediaType.APPLICATION_JSON_VALUE
}
if (headers[HttpHeaders.ACCEPT].isNullOrEmpty()) {
headers[HttpHeaders.ACCEPT] = MediaType.APPLICATION_JSON_VALUE
}
}
protected fun encodeURIComponent(uriComponent: kotlin.String) =
UriUtils.encodeFragment(uriComponent, Charsets.UTF_8)
private fun <I> RestClient.method(requestConfig: RequestConfig<I>)=
method(HttpMethod.valueOf(requestConfig.method.name))
private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>) =
uri { builder ->
builder.path(requestConfig.path).apply {
requestConfig.query.forEach { (name, value) ->
queryParam(name, value)
}
}.build()
}
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>) =
apply { if (requestConfig.body != null) body(requestConfig.body) }
}
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
/*
.replace("\"", "") converts the json object string to an actual string for the query parameter.
The moshi or gson adapter allows a more generic solution instead of trying to use a native
formatter. It also easily allows to provide a simple way to define a custom date format pattern
inside a gson/moshi adapter.
*/
return Serializer.jacksonObjectMapper.writeValueAsString(value).replace("\"", "")
}

View File

@@ -0,0 +1,11 @@
package org.openapitools.client.infrastructure
/**
* Defines a config object for a given part of a multi-part request.
* NOTE: Headers is a Map<String,String> because rfc2616 defines
* multi-valued headers as csv-only.
*/
data class PartConfig<T>(
val headers: MutableMap<String, String> = mutableMapOf(),
val body: T? = null
)

View File

@@ -0,0 +1,18 @@
package org.openapitools.client.infrastructure
/**
* Defines a config object for a given request.
* NOTE: This object doesn't include 'body' because it
* allows for caching of the constructed object
* for many request definitions.
* NOTE: Headers is a Map<String,String> because rfc2616 defines
* multi-valued headers as csv-only.
*/
data class RequestConfig<T>(
val method: RequestMethod,
val path: String,
val headers: MutableMap<String, String> = mutableMapOf(),
val query: MutableMap<String, List<String>> = mutableMapOf(),
val requiresAuthentication: Boolean,
val body: T? = null
)

View File

@@ -0,0 +1,8 @@
package org.openapitools.client.infrastructure
/**
* Provides enumerated HTTP verbs
*/
enum class RequestMethod {
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
}

View File

@@ -0,0 +1,14 @@
package org.openapitools.client.infrastructure
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
object Serializer {
@JvmStatic
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
.findAndRegisterModules()
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
}

View File

@@ -0,0 +1,38 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.fasterxml.jackson.annotation.JsonProperty
/**
* A category for a pet
*
* @param id
* @param name
*/
data class Category (
@field:JsonProperty("id")
val id: kotlin.Long? = null,
@field:JsonProperty("name")
val name: kotlin.String? = null
)

View File

@@ -0,0 +1,42 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.fasterxml.jackson.annotation.JsonProperty
/**
* Describes the result of uploading an image resource
*
* @param code
* @param type
* @param message
*/
data class ModelApiResponse (
@field:JsonProperty("code")
val code: kotlin.Int? = null,
@field:JsonProperty("type")
val type: kotlin.String? = null,
@field:JsonProperty("message")
val message: kotlin.String? = null
)

View File

@@ -0,0 +1,68 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.fasterxml.jackson.annotation.JsonProperty
/**
* An order for a pets from the pet store
*
* @param id
* @param petId
* @param quantity
* @param shipDate
* @param status Order Status
* @param complete
*/
data class Order (
@field:JsonProperty("id")
val id: kotlin.Long? = null,
@field:JsonProperty("petId")
val petId: kotlin.Long? = null,
@field:JsonProperty("quantity")
val quantity: kotlin.Int? = null,
@field:JsonProperty("shipDate")
val shipDate: java.time.OffsetDateTime? = null,
/* Order Status */
@field:JsonProperty("status")
val status: Order.Status? = null,
@field:JsonProperty("complete")
val complete: kotlin.Boolean? = false
) {
/**
* Order Status
*
* Values: placed,approved,delivered,unknownDefaultOpenApi
*/
enum class Status(val value: kotlin.String) {
@JsonProperty(value = "placed") placed("placed"),
@JsonProperty(value = "approved") approved("approved"),
@JsonProperty(value = "delivered") delivered("delivered"),
@JsonProperty(value = "unknown_default_open_api") unknownDefaultOpenApi("unknown_default_open_api");
}
}

View File

@@ -0,0 +1,71 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import org.openapitools.client.models.Category
import org.openapitools.client.models.Tag
import com.fasterxml.jackson.annotation.JsonProperty
/**
* A pet for sale in the pet store
*
* @param name
* @param photoUrls
* @param id
* @param category
* @param tags
* @param status pet status in the store
*/
data class Pet (
@field:JsonProperty("name")
val name: kotlin.String,
@field:JsonProperty("photoUrls")
val photoUrls: kotlin.collections.List<kotlin.String>,
@field:JsonProperty("id")
val id: kotlin.Long? = null,
@field:JsonProperty("category")
val category: Category? = null,
@field:JsonProperty("tags")
val tags: kotlin.collections.List<Tag>? = null,
/* pet status in the store */
@field:JsonProperty("status")
@Deprecated(message = "This property is deprecated.")
val status: Pet.Status? = null
) {
/**
* pet status in the store
*
* Values: available,pending,sold,unknownDefaultOpenApi
*/
enum class Status(val value: kotlin.String) {
@JsonProperty(value = "available") available("available"),
@JsonProperty(value = "pending") pending("pending"),
@JsonProperty(value = "sold") sold("sold"),
@JsonProperty(value = "unknown_default_open_api") unknownDefaultOpenApi("unknown_default_open_api");
}
}

View File

@@ -0,0 +1,38 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.fasterxml.jackson.annotation.JsonProperty
/**
* A tag for a pet
*
* @param id
* @param name
*/
data class Tag (
@field:JsonProperty("id")
val id: kotlin.Long? = null,
@field:JsonProperty("name")
val name: kotlin.String? = null
)

View File

@@ -0,0 +1,63 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.fasterxml.jackson.annotation.JsonProperty
/**
* A User who is purchasing from the pet store
*
* @param id
* @param username
* @param firstName
* @param lastName
* @param email
* @param password
* @param phone
* @param userStatus User Status
*/
data class User (
@field:JsonProperty("id")
val id: kotlin.Long? = null,
@field:JsonProperty("username")
val username: kotlin.String? = null,
@field:JsonProperty("firstName")
val firstName: kotlin.String? = null,
@field:JsonProperty("lastName")
val lastName: kotlin.String? = null,
@field:JsonProperty("email")
val email: kotlin.String? = null,
@field:JsonProperty("password")
val password: kotlin.String? = null,
@field:JsonProperty("phone")
val phone: kotlin.String? = null,
/* User Status */
@field:JsonProperty("userStatus")
val userStatus: kotlin.Int? = null
)