forked from loafle/openapi-generator-original
remove the bin folder under kotlin samples (#8520)
This commit is contained in:
parent
5f2ca61862
commit
9286b43dfa
@ -1,374 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.ApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("status", toMultiValue(status.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByStatus",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Pet>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @return ApiResponse
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<User>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as User
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return kotlin.String
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
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))
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
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
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
protected const val ContentType = "Content-Type"
|
||||
protected const val Accept = "Accept"
|
||||
protected const val Authorization = "Authorization"
|
||||
protected const val JsonMediaType = "application/json"
|
||||
protected const val FormDataMediaType = "multipart/form-data"
|
||||
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||
protected const val XmlMediaType = "application/xml"
|
||||
|
||||
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||
var username: String? = null
|
||||
var password: String? = null
|
||||
var accessToken: String? = null
|
||||
|
||||
@JvmStatic
|
||||
val client: OkHttpClient by lazy {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||
*
|
||||
* @param file The given file
|
||||
* @return The guessed Content-Type
|
||||
*/
|
||||
protected fun guessContentTypeFromFile(file: File): String {
|
||||
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||
return contentType ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
if (value is File) {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\"; filename=\"${value.name}\""
|
||||
)
|
||||
val fileMediaType = guessContentTypeFromFile(value).toMediaTypeOrNull()
|
||||
addPart(partHeaders, value.asRequestBody(fileMediaType))
|
||||
} else {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\""
|
||||
)
|
||||
addPart(
|
||||
partHeaders,
|
||||
parameterToString(value).toRequestBody(null)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == FormUrlEncMediaType -> {
|
||||
FormBody.Builder().apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
add(key, parameterToString(value))
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> Serializer.gson.toJson(content, T::class.java).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.")
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
}
|
||||
val bodyContent = body.string()
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.gson.fromJson(bodyContent, T::class.java)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
|
||||
} else {
|
||||
requestConfig.headers["api_key"] = apiKey["api_key"]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||
accessToken?.let { accessToken ->
|
||||
requestConfig.headers[Authorization] = "Bearer $accessToken "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
addQueryParameter(query.key, queryValue)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
|
||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||
requestConfig.headers[ContentType] = JsonMediaType
|
||||
}
|
||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||
requestConfig.headers[Accept] = JsonMediaType
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||
}.apply {
|
||||
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return 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 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.gson.toJson(value, T::class.java).replace("\"", "")
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
enum class ResponseType {
|
||||
Success, Informational, Redirection, ClientError, ServerError
|
||||
}
|
||||
|
||||
interface Response
|
||||
|
||||
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
|
||||
abstract val statusCode: Int
|
||||
abstract val headers: Map<String,List<String>>
|
||||
}
|
||||
|
||||
class Success<T>(
|
||||
val data: T,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
): ApiInfrastructureResponse<T>(ResponseType.Success)
|
||||
|
||||
class Informational<T>(
|
||||
val statusText: String,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
|
||||
|
||||
class Redirection<T>(
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
|
||||
|
||||
class ClientError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
|
||||
|
||||
class ServerError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>>
|
||||
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
|
@ -1,29 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object ApplicationDelegates {
|
||||
/**
|
||||
* Provides a property delegate, allowing the property to be set once and only once.
|
||||
*
|
||||
* If unset (no default value), a get on the property will throw [IllegalStateException].
|
||||
*/
|
||||
fun <T> setOnce(defaultValue: T? = null) : ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
|
||||
|
||||
private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
|
||||
private var isSet = false
|
||||
private var value: T? = defaultValue
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value ?: throw IllegalStateException("${property.name} not initialized")
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
|
||||
if (!isSet) {
|
||||
this.value = value
|
||||
isSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import com.google.gson.stream.JsonToken.NULL
|
||||
import java.io.IOException
|
||||
|
||||
class ByteArrayAdapter : TypeAdapter<ByteArray>() {
|
||||
@Throws(IOException::class)
|
||||
override fun write(out: JsonWriter?, value: ByteArray?) {
|
||||
if (value == null) {
|
||||
out?.nullValue()
|
||||
} else {
|
||||
out?.value(String(value))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(out: JsonReader?): ByteArray? {
|
||||
out ?: return null
|
||||
|
||||
when (out.peek()) {
|
||||
NULL -> {
|
||||
out.nextNull()
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
return out.nextString().toByteArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import com.google.gson.stream.JsonToken.NULL
|
||||
import java.io.IOException
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class DateAdapter(val formatter: DateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault())) : TypeAdapter<Date>() {
|
||||
@Throws(IOException::class)
|
||||
override fun write(out: JsonWriter?, value: Date?) {
|
||||
if (value == null) {
|
||||
out?.nullValue()
|
||||
} else {
|
||||
out?.value(formatter.format(value))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(out: JsonReader?): Date? {
|
||||
out ?: return null
|
||||
|
||||
when (out.peek()) {
|
||||
NULL -> {
|
||||
out.nextNull()
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
return formatter.parse(out.nextString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
@file:Suppress("unused")
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import com.google.gson.stream.JsonToken.NULL
|
||||
import java.io.IOException
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE) : TypeAdapter<LocalDate>() {
|
||||
@Throws(IOException::class)
|
||||
override fun write(out: JsonWriter?, value: LocalDate?) {
|
||||
if (value == null) {
|
||||
out?.nullValue()
|
||||
} else {
|
||||
out?.value(formatter.format(value))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(out: JsonReader?): LocalDate? {
|
||||
out ?: return null
|
||||
|
||||
when (out.peek()) {
|
||||
NULL -> {
|
||||
out.nextNull()
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
return LocalDate.parse(out.nextString(), formatter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import com.google.gson.stream.JsonToken.NULL
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME) : TypeAdapter<LocalDateTime>() {
|
||||
@Throws(IOException::class)
|
||||
override fun write(out: JsonWriter?, value: LocalDateTime?) {
|
||||
if (value == null) {
|
||||
out?.nullValue()
|
||||
} else {
|
||||
out?.value(formatter.format(value))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(out: JsonReader?): LocalDateTime? {
|
||||
out ?: return null
|
||||
|
||||
when (out.peek()) {
|
||||
NULL -> {
|
||||
out.nextNull()
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
return LocalDateTime.parse(out.nextString(), formatter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import com.google.gson.stream.JsonToken.NULL
|
||||
import java.io.IOException
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class OffsetDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME) : TypeAdapter<OffsetDateTime>() {
|
||||
@Throws(IOException::class)
|
||||
override fun write(out: JsonWriter?, value: OffsetDateTime?) {
|
||||
if (value == null) {
|
||||
out?.nullValue()
|
||||
} else {
|
||||
out?.value(formatter.format(value))
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(out: JsonReader?): OffsetDateTime? {
|
||||
out ?: return null
|
||||
|
||||
when (out.peek()) {
|
||||
NULL -> {
|
||||
out.nextNull()
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
return OffsetDateTime.parse(out.nextString(), formatter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf()
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
/**
|
||||
* Provides enumerated HTTP verbs
|
||||
*/
|
||||
enum class RequestMethod {
|
||||
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 1xx code
|
||||
*/
|
||||
val Response.isInformational : Boolean get() = this.code in 100..199
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 3xx code
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
val Response.isRedirect : Boolean get() = this.code in 300..399
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 4xx code
|
||||
*/
|
||||
val Response.isClientError : Boolean get() = this.code in 400..499
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
||||
*/
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
@ -1,24 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.OffsetDateTime
|
||||
import java.util.UUID
|
||||
import java.util.Date
|
||||
|
||||
object Serializer {
|
||||
@JvmStatic
|
||||
val gsonBuilder: GsonBuilder = GsonBuilder()
|
||||
.registerTypeAdapter(Date::class.java, DateAdapter())
|
||||
.registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
|
||||
.registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
|
||||
.registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
|
||||
.registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter())
|
||||
|
||||
@JvmStatic
|
||||
val gson: Gson by lazy {
|
||||
gsonBuilder.create()
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param type
|
||||
* @param message
|
||||
*/
|
||||
|
||||
data class ApiResponse (
|
||||
@SerializedName("code")
|
||||
val code: kotlin.Int? = null,
|
||||
@SerializedName("type")
|
||||
val type: kotlin.String? = null,
|
||||
@SerializedName("message")
|
||||
val message: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
|
||||
data class Category (
|
||||
@SerializedName("id")
|
||||
val id: kotlin.Long? = null,
|
||||
@SerializedName("name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@SerializedName("id")
|
||||
val id: kotlin.Long? = null,
|
||||
@SerializedName("petId")
|
||||
val petId: kotlin.Long? = null,
|
||||
@SerializedName("quantity")
|
||||
val quantity: kotlin.Int? = null,
|
||||
@SerializedName("shipDate")
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
@SerializedName("status")
|
||||
val status: Order.Status? = null,
|
||||
@SerializedName("complete")
|
||||
val complete: kotlin.Boolean? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* Values: placed,approved,delivered
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@SerializedName(value = "placed") placed("placed"),
|
||||
@SerializedName(value = "approved") approved("approved"),
|
||||
@SerializedName(value = "delivered") delivered("delivered");
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
import org.openapitools.client.models.Category
|
||||
import org.openapitools.client.models.Tag
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@SerializedName("name")
|
||||
val name: kotlin.String,
|
||||
@SerializedName("photoUrls")
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
@SerializedName("id")
|
||||
val id: kotlin.Long? = null,
|
||||
@SerializedName("category")
|
||||
val category: Category? = null,
|
||||
@SerializedName("tags")
|
||||
val tags: kotlin.collections.List<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
@SerializedName("status")
|
||||
val status: Pet.Status? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* Values: available,pending,sold
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@SerializedName(value = "available") available("available"),
|
||||
@SerializedName(value = "pending") pending("pending"),
|
||||
@SerializedName(value = "sold") sold("sold");
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
|
||||
data class Tag (
|
||||
@SerializedName("id")
|
||||
val id: kotlin.Long? = null,
|
||||
@SerializedName("name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@SerializedName("id")
|
||||
val id: kotlin.Long? = null,
|
||||
@SerializedName("username")
|
||||
val username: kotlin.String? = null,
|
||||
@SerializedName("firstName")
|
||||
val firstName: kotlin.String? = null,
|
||||
@SerializedName("lastName")
|
||||
val lastName: kotlin.String? = null,
|
||||
@SerializedName("email")
|
||||
val email: kotlin.String? = null,
|
||||
@SerializedName("password")
|
||||
val password: kotlin.String? = null,
|
||||
@SerializedName("phone")
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
@SerializedName("userStatus")
|
||||
val userStatus: kotlin.Int? = null
|
||||
)
|
||||
|
@ -1,20 +0,0 @@
|
||||
package org.openapitools
|
||||
|
||||
import org.openapitools.client.apis.PetApi
|
||||
import org.openapitools.client.apis.StoreApi
|
||||
import org.openapitools.client.models.Category
|
||||
import org.openapitools.client.models.Pet
|
||||
import org.openapitools.client.models.Tag
|
||||
|
||||
fun main() {
|
||||
println("<top>.main")
|
||||
val inventory = StoreApi().getInventory()
|
||||
println("Inventory : $inventory")
|
||||
val pet = Pet(name = "Elliot", photoUrls = listOf<String>("https://jameshooverstudios.com/wp-content/uploads/2015/04/Majestic-Dog-Photography-Elliot-Nov-5-2014.jpg", "https://express-images.franklymedia.com/6616/sites/981/2020/01/22105725/Elliott.jpg"), id = 123456453, category = Category(id = 13259476, name = "dog"), tags = listOf<Tag>(Tag(id = 194093, name = "Elliot")), status = Pet.Status.AVAILABLE)
|
||||
PetApi().addPet(pet)
|
||||
val elliot = PetApi().getPetById(123456453)
|
||||
println("Elliot : $elliot")
|
||||
assert(pet == elliot)
|
||||
println("<bottom>.main")
|
||||
|
||||
}
|
@ -1,374 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.ApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("status", toMultiValue(status.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByStatus",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Pet>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @return ApiResponse
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<User>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as User
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return kotlin.String
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
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))
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
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
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
protected const val ContentType = "Content-Type"
|
||||
protected const val Accept = "Accept"
|
||||
protected const val Authorization = "Authorization"
|
||||
protected const val JsonMediaType = "application/json"
|
||||
protected const val FormDataMediaType = "multipart/form-data"
|
||||
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||
protected const val XmlMediaType = "application/xml"
|
||||
|
||||
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||
var username: String? = null
|
||||
var password: String? = null
|
||||
var accessToken: String? = null
|
||||
|
||||
@JvmStatic
|
||||
val client: OkHttpClient by lazy {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||
*
|
||||
* @param file The given file
|
||||
* @return The guessed Content-Type
|
||||
*/
|
||||
protected fun guessContentTypeFromFile(file: File): String {
|
||||
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||
return contentType ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
if (value is File) {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\"; filename=\"${value.name}\""
|
||||
)
|
||||
val fileMediaType = guessContentTypeFromFile(value).toMediaTypeOrNull()
|
||||
addPart(partHeaders, value.asRequestBody(fileMediaType))
|
||||
} else {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\""
|
||||
)
|
||||
addPart(
|
||||
partHeaders,
|
||||
parameterToString(value).toRequestBody(null)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == FormUrlEncMediaType -> {
|
||||
FormBody.Builder().apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
add(key, parameterToString(value))
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> Serializer.jacksonObjectMapper.writeValueAsString(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.")
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
}
|
||||
val bodyContent = body.string()
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.jacksonObjectMapper.readValue(bodyContent, T::class.java)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
|
||||
} else {
|
||||
requestConfig.headers["api_key"] = apiKey["api_key"]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||
accessToken?.let { accessToken ->
|
||||
requestConfig.headers[Authorization] = "Bearer $accessToken "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
addQueryParameter(query.key, queryValue)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
|
||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||
requestConfig.headers[ContentType] = JsonMediaType
|
||||
}
|
||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||
requestConfig.headers[Accept] = JsonMediaType
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||
}.apply {
|
||||
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return 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 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("\"", "")
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
enum class ResponseType {
|
||||
Success, Informational, Redirection, ClientError, ServerError
|
||||
}
|
||||
|
||||
interface Response
|
||||
|
||||
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
|
||||
abstract val statusCode: Int
|
||||
abstract val headers: Map<String,List<String>>
|
||||
}
|
||||
|
||||
class Success<T>(
|
||||
val data: T,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
): ApiInfrastructureResponse<T>(ResponseType.Success)
|
||||
|
||||
class Informational<T>(
|
||||
val statusText: String,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
|
||||
|
||||
class Redirection<T>(
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
|
||||
|
||||
class ClientError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
|
||||
|
||||
class ServerError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>>
|
||||
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
|
@ -1,29 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object ApplicationDelegates {
|
||||
/**
|
||||
* Provides a property delegate, allowing the property to be set once and only once.
|
||||
*
|
||||
* If unset (no default value), a get on the property will throw [IllegalStateException].
|
||||
*/
|
||||
fun <T> setOnce(defaultValue: T? = null) : ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
|
||||
|
||||
private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
|
||||
private var isSet = false
|
||||
private var value: T? = defaultValue
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value ?: throw IllegalStateException("${property.name} not initialized")
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
|
||||
if (!isSet) {
|
||||
this.value = value
|
||||
isSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
@file:Suppress("unused")
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf()
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
/**
|
||||
* Provides enumerated HTTP verbs
|
||||
*/
|
||||
enum class RequestMethod {
|
||||
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 1xx code
|
||||
*/
|
||||
val Response.isInformational : Boolean get() = this.code in 100..199
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 3xx code
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
val Response.isRedirect : Boolean get() = this.code in 300..399
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 4xx code
|
||||
*/
|
||||
val Response.isClientError : Boolean get() = this.code in 400..499
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
||||
*/
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
@ -1,18 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import java.util.Date
|
||||
|
||||
object Serializer {
|
||||
@JvmStatic
|
||||
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
|
||||
.registerModule(Jdk8Module())
|
||||
.registerModule(JavaTimeModule())
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
|
||||
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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 ApiResponse (
|
||||
@field:JsonProperty("code")
|
||||
val code: kotlin.Int? = null,
|
||||
@field:JsonProperty("type")
|
||||
val type: kotlin.String? = null,
|
||||
@field:JsonProperty("message")
|
||||
val message: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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
|
||||
)
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* Values: PLACED,APPROVED,DELIVERED
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@JsonProperty(value = "placed") PLACED("placed"),
|
||||
@JsonProperty(value = "approved") APPROVED("approved"),
|
||||
@JsonProperty(value = "delivered") DELIVERED("delivered");
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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")
|
||||
val status: Pet.Status? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* Values: AVAILABLE,PENDING,SOLD
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@JsonProperty(value = "available") AVAILABLE("available"),
|
||||
@JsonProperty(value = "pending") PENDING("pending"),
|
||||
@JsonProperty(value = "sold") SOLD("sold");
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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
|
||||
)
|
||||
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
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
|
||||
)
|
||||
|
@ -1,376 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.ApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pets
|
||||
*
|
||||
* @param lastUpdated When this endpoint was hit last to help indentify if the client already has the latest copy. (optional)
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getAllPets(lastUpdated: java.time.OffsetDateTime?) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
if (lastUpdated != null) {
|
||||
put("lastUpdated", listOf(parseDateToQueryString(lastUpdated)))
|
||||
}
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/getAll",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Pet>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @return ApiResponse
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<User>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as User
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return kotlin.String
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
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))
|
||||
}
|
||||
}
|
@ -1,245 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
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
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
protected const val ContentType = "Content-Type"
|
||||
protected const val Accept = "Accept"
|
||||
protected const val Authorization = "Authorization"
|
||||
protected const val JsonMediaType = "application/json"
|
||||
protected const val FormDataMediaType = "multipart/form-data"
|
||||
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||
protected const val XmlMediaType = "application/xml"
|
||||
|
||||
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||
var username: String? = null
|
||||
var password: String? = null
|
||||
var accessToken: String? = null
|
||||
|
||||
@JvmStatic
|
||||
val client: OkHttpClient by lazy {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||
*
|
||||
* @param file The given file
|
||||
* @return The guessed Content-Type
|
||||
*/
|
||||
protected fun guessContentTypeFromFile(file: File): String {
|
||||
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||
return contentType ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
if (value is File) {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\"; filename=\"${value.name}\""
|
||||
)
|
||||
val fileMediaType = guessContentTypeFromFile(value).toMediaTypeOrNull()
|
||||
addPart(partHeaders, value.asRequestBody(fileMediaType))
|
||||
} else {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\""
|
||||
)
|
||||
addPart(
|
||||
partHeaders,
|
||||
parameterToString(value).toRequestBody(null)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == FormUrlEncMediaType -> {
|
||||
FormBody.Builder().apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
add(key, parameterToString(value))
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> 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.")
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
}
|
||||
val bodyContent = body.string()
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
|
||||
} else {
|
||||
requestConfig.headers["api_key"] = apiKey["api_key"]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||
accessToken?.let { accessToken ->
|
||||
requestConfig.headers[Authorization] = "Bearer $accessToken "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
addQueryParameter(query.key, queryValue)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
|
||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||
requestConfig.headers[ContentType] = JsonMediaType
|
||||
}
|
||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||
requestConfig.headers[Accept] = JsonMediaType
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||
}.apply {
|
||||
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return 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 inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||
return value.toString()
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
enum class ResponseType {
|
||||
Success, Informational, Redirection, ClientError, ServerError
|
||||
}
|
||||
|
||||
interface Response
|
||||
|
||||
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
|
||||
abstract val statusCode: Int
|
||||
abstract val headers: Map<String,List<String>>
|
||||
}
|
||||
|
||||
class Success<T>(
|
||||
val data: T,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
): ApiInfrastructureResponse<T>(ResponseType.Success)
|
||||
|
||||
class Informational<T>(
|
||||
val statusText: String,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
|
||||
|
||||
class Redirection<T>(
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
|
||||
|
||||
class ClientError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
|
||||
|
||||
class ServerError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>>
|
||||
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
|
@ -1,29 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object ApplicationDelegates {
|
||||
/**
|
||||
* Provides a property delegate, allowing the property to be set once and only once.
|
||||
*
|
||||
* If unset (no default value), a get on the property will throw [IllegalStateException].
|
||||
*/
|
||||
fun <T> setOnce(defaultValue: T? = null) : ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
|
||||
|
||||
private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
|
||||
private var isSet = false
|
||||
private var value: T? = defaultValue
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value ?: throw IllegalStateException("${property.name} not initialized")
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
|
||||
if (!isSet) {
|
||||
this.value = value
|
||||
isSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
class ByteArrayAdapter {
|
||||
@ToJson
|
||||
fun toJson(data: ByteArray): String = String(data)
|
||||
|
||||
@FromJson
|
||||
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
@file:Suppress("unused")
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDate): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDate {
|
||||
return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDateTime): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDateTime {
|
||||
return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class OffsetDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: OffsetDateTime): String {
|
||||
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): OffsetDateTime {
|
||||
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf()
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
/**
|
||||
* Provides enumerated HTTP verbs
|
||||
*/
|
||||
enum class RequestMethod {
|
||||
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 1xx code
|
||||
*/
|
||||
val Response.isInformational : Boolean get() = this.code in 100..199
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 3xx code
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
val Response.isRedirect : Boolean get() = this.code in 300..399
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 4xx code
|
||||
*/
|
||||
val Response.isClientError : Boolean get() = this.code in 400..499
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
||||
*/
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
@ -1,23 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import java.util.Date
|
||||
|
||||
object Serializer {
|
||||
@JvmStatic
|
||||
val moshiBuilder: Moshi.Builder = Moshi.Builder()
|
||||
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
|
||||
.add(OffsetDateTimeAdapter())
|
||||
.add(LocalDateTimeAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
|
||||
@JvmStatic
|
||||
val moshi: Moshi by lazy {
|
||||
moshiBuilder.build()
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.util.UUID
|
||||
|
||||
class UUIDAdapter {
|
||||
@ToJson
|
||||
fun toJson(uuid: UUID) = uuid.toString()
|
||||
|
||||
@FromJson
|
||||
fun fromJson(s: String) = UUID.fromString(s)
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param type
|
||||
* @param message
|
||||
*/
|
||||
|
||||
data class ApiResponse (
|
||||
@Json(name = "code")
|
||||
val code: kotlin.Int? = null,
|
||||
@Json(name = "type")
|
||||
val type: kotlin.String? = null,
|
||||
@Json(name = "message")
|
||||
val message: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
|
||||
data class Category (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "petId")
|
||||
val petId: kotlin.Long? = null,
|
||||
@Json(name = "quantity")
|
||||
val quantity: kotlin.Int? = null,
|
||||
@Json(name = "shipDate")
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
@Json(name = "status")
|
||||
val status: Order.Status? = null,
|
||||
@Json(name = "complete")
|
||||
val complete: kotlin.Boolean? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* Values: placed,approved,delivered
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "placed") placed("placed"),
|
||||
@Json(name = "approved") approved("approved"),
|
||||
@Json(name = "delivered") delivered("delivered");
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
import org.openapitools.client.models.Category
|
||||
import org.openapitools.client.models.Tag
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String,
|
||||
@Json(name = "photoUrls")
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "category")
|
||||
val category: Category? = null,
|
||||
@Json(name = "tags")
|
||||
val tags: kotlin.collections.List<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
@Json(name = "status")
|
||||
val status: Pet.Status? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* Values: available,pending,sold
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "available") available("available"),
|
||||
@Json(name = "pending") pending("pending"),
|
||||
@Json(name = "sold") sold("sold");
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
|
||||
data class Tag (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "username")
|
||||
val username: kotlin.String? = null,
|
||||
@Json(name = "firstName")
|
||||
val firstName: kotlin.String? = null,
|
||||
@Json(name = "lastName")
|
||||
val lastName: kotlin.String? = null,
|
||||
@Json(name = "email")
|
||||
val email: kotlin.String? = null,
|
||||
@Json(name = "password")
|
||||
val password: kotlin.String? = null,
|
||||
@Json(name = "phone")
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
@Json(name = "userStatus")
|
||||
val userStatus: kotlin.Int? = null
|
||||
)
|
||||
|
@ -1,374 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.ApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("status", toMultiValue(status.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByStatus",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Pet>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @return ApiResponse
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<User>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as User
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return kotlin.String
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
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))
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
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
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
protected const val ContentType = "Content-Type"
|
||||
protected const val Accept = "Accept"
|
||||
protected const val Authorization = "Authorization"
|
||||
protected const val JsonMediaType = "application/json"
|
||||
protected const val FormDataMediaType = "multipart/form-data"
|
||||
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||
protected const val XmlMediaType = "application/xml"
|
||||
|
||||
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||
var username: String? = null
|
||||
var password: String? = null
|
||||
var accessToken: String? = null
|
||||
|
||||
@JvmStatic
|
||||
val client: OkHttpClient by lazy {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||
*
|
||||
* @param file The given file
|
||||
* @return The guessed Content-Type
|
||||
*/
|
||||
protected fun guessContentTypeFromFile(file: File): String {
|
||||
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||
return contentType ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
if (value is File) {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\"; filename=\"${value.name}\""
|
||||
)
|
||||
val fileMediaType = guessContentTypeFromFile(value).toMediaTypeOrNull()
|
||||
addPart(partHeaders, value.asRequestBody(fileMediaType))
|
||||
} else {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\""
|
||||
)
|
||||
addPart(
|
||||
partHeaders,
|
||||
parameterToString(value).toRequestBody(null)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == FormUrlEncMediaType -> {
|
||||
FormBody.Builder().apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
add(key, parameterToString(value))
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> 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.")
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
}
|
||||
val bodyContent = body.string()
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
|
||||
} else {
|
||||
requestConfig.headers["api_key"] = apiKey["api_key"]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||
accessToken?.let { accessToken ->
|
||||
requestConfig.headers[Authorization] = "Bearer $accessToken "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
addQueryParameter(query.key, queryValue)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
|
||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||
requestConfig.headers[ContentType] = JsonMediaType
|
||||
}
|
||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||
requestConfig.headers[Accept] = JsonMediaType
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||
}.apply {
|
||||
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return 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 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.moshi.adapter(T::class.java).toJson(value).replace("\"", "")
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
enum class ResponseType {
|
||||
Success, Informational, Redirection, ClientError, ServerError
|
||||
}
|
||||
|
||||
interface Response
|
||||
|
||||
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
|
||||
abstract val statusCode: Int
|
||||
abstract val headers: Map<String,List<String>>
|
||||
}
|
||||
|
||||
class Success<T>(
|
||||
val data: T,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
): ApiInfrastructureResponse<T>(ResponseType.Success)
|
||||
|
||||
class Informational<T>(
|
||||
val statusText: String,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
|
||||
|
||||
class Redirection<T>(
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
|
||||
|
||||
class ClientError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
|
||||
|
||||
class ServerError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>>
|
||||
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
|
@ -1,29 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object ApplicationDelegates {
|
||||
/**
|
||||
* Provides a property delegate, allowing the property to be set once and only once.
|
||||
*
|
||||
* If unset (no default value), a get on the property will throw [IllegalStateException].
|
||||
*/
|
||||
fun <T> setOnce(defaultValue: T? = null) : ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
|
||||
|
||||
private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
|
||||
private var isSet = false
|
||||
private var value: T? = defaultValue
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value ?: throw IllegalStateException("${property.name} not initialized")
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
|
||||
if (!isSet) {
|
||||
this.value = value
|
||||
isSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
class ByteArrayAdapter {
|
||||
@ToJson
|
||||
fun toJson(data: ByteArray): String = String(data)
|
||||
|
||||
@FromJson
|
||||
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
@file:Suppress("unused")
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDate): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDate {
|
||||
return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class LocalDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDateTime): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDateTime {
|
||||
return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class OffsetDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: OffsetDateTime): String {
|
||||
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): OffsetDateTime {
|
||||
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf()
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
/**
|
||||
* Provides enumerated HTTP verbs
|
||||
*/
|
||||
enum class RequestMethod {
|
||||
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 1xx code
|
||||
*/
|
||||
val Response.isInformational : Boolean get() = this.code in 100..199
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 3xx code
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
val Response.isRedirect : Boolean get() = this.code in 300..399
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 4xx code
|
||||
*/
|
||||
val Response.isClientError : Boolean get() = this.code in 400..499
|
||||
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
||||
*/
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
@ -1,21 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
|
||||
import java.util.Date
|
||||
|
||||
object Serializer {
|
||||
@JvmStatic
|
||||
val moshiBuilder: Moshi.Builder = Moshi.Builder()
|
||||
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
|
||||
.add(OffsetDateTimeAdapter())
|
||||
.add(LocalDateTimeAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
|
||||
@JvmStatic
|
||||
val moshi: Moshi by lazy {
|
||||
moshiBuilder.build()
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.util.UUID
|
||||
|
||||
class UUIDAdapter {
|
||||
@ToJson
|
||||
fun toJson(uuid: UUID) = uuid.toString()
|
||||
|
||||
@FromJson
|
||||
fun fromJson(s: String) = UUID.fromString(s)
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param type
|
||||
* @param message
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class ApiResponse (
|
||||
@Json(name = "code")
|
||||
val code: kotlin.Int? = null,
|
||||
@Json(name = "type")
|
||||
val type: kotlin.String? = null,
|
||||
@Json(name = "message")
|
||||
val message: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Category (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
* @param id
|
||||
* @param petId
|
||||
* @param quantity
|
||||
* @param shipDate
|
||||
* @param status Order Status
|
||||
* @param complete
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Order (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "petId")
|
||||
val petId: kotlin.Long? = null,
|
||||
@Json(name = "quantity")
|
||||
val quantity: kotlin.Int? = null,
|
||||
@Json(name = "shipDate")
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
@Json(name = "status")
|
||||
val status: Order.Status? = null,
|
||||
@Json(name = "complete")
|
||||
val complete: kotlin.Boolean? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* Values: placed,approved,delivered
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "placed") placed("placed"),
|
||||
@Json(name = "approved") approved("approved"),
|
||||
@Json(name = "delivered") delivered("delivered");
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
import org.openapitools.client.models.Category
|
||||
import org.openapitools.client.models.Tag
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Pet (
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String,
|
||||
@Json(name = "photoUrls")
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "category")
|
||||
val category: Category? = null,
|
||||
@Json(name = "tags")
|
||||
val tags: kotlin.collections.List<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
@Json(name = "status")
|
||||
val status: Pet.Status? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* Values: available,pending,sold
|
||||
*/
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "available") available("available"),
|
||||
@Json(name = "pending") pending("pending"),
|
||||
@Json(name = "sold") sold("sold");
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Tag (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.models
|
||||
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class User (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "username")
|
||||
val username: kotlin.String? = null,
|
||||
@Json(name = "firstName")
|
||||
val firstName: kotlin.String? = null,
|
||||
@Json(name = "lastName")
|
||||
val lastName: kotlin.String? = null,
|
||||
@Json(name = "email")
|
||||
val email: kotlin.String? = null,
|
||||
@Json(name = "password")
|
||||
val password: kotlin.String? = null,
|
||||
@Json(name = "phone")
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
@Json(name = "userStatus")
|
||||
val userStatus: kotlin.Int? = null
|
||||
)
|
||||
|
@ -1,374 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.ApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun addPet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||
.apply {
|
||||
put("status", toMultiValue(status.toList(), "csv"))
|
||||
}
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByStatus",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return kotlin.collections.List<Pet>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
@Deprecated(message = "This operation is deprecated.")
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/pet/findByTags",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getPetById(petId: kotlin.Long) : Pet {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Pet>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePet(body: Pet) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/pet",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @return ApiResponse
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.POST,
|
||||
"/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<ApiResponse>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteOrder(orderId: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/inventory",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.collections.Map<kotlin.String, kotlin.Int>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getOrderById(orderId: kotlin.Long) : Order {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun placeOrder(body: Order) : Order {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/store/order",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Order>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as Order
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.apis
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
import org.openapitools.client.infrastructure.ApiClient
|
||||
import org.openapitools.client.infrastructure.ClientException
|
||||
import org.openapitools.client.infrastructure.ClientError
|
||||
import org.openapitools.client.infrastructure.ServerException
|
||||
import org.openapitools.client.infrastructure.ServerError
|
||||
import org.openapitools.client.infrastructure.MultiValueMap
|
||||
import org.openapitools.client.infrastructure.RequestConfig
|
||||
import org.openapitools.client.infrastructure.RequestMethod
|
||||
import org.openapitools.client.infrastructure.ResponseType
|
||||
import org.openapitools.client.infrastructure.Success
|
||||
import org.openapitools.client.infrastructure.toMultiValue
|
||||
|
||||
internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val defaultBasePath: String by lazy {
|
||||
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUser(body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithArray",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.POST,
|
||||
"/user/createWithList",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun deleteUser(username: kotlin.String) : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.DELETE,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getUserByName(username: kotlin.String) : User {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<User>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as User
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return kotlin.String
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||
val localVariableBody: kotlin.Any? = 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(
|
||||
RequestMethod.GET,
|
||||
"/user/login",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<kotlin.String>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun logoutUser() : Unit {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
"/user/logout",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun updateUser(username: kotlin.String, body: User) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.PUT,
|
||||
"/user/{username}".replace("{"+"username"+"}", "$username"),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val localVarResponse = request<Any?>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> Unit
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
internal typealias MultiValueMap = MutableMap<String,List<String>>
|
||||
|
||||
internal fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
|
||||
"csv" -> ","
|
||||
"tsv" -> "\t"
|
||||
"pipe" -> "|"
|
||||
"space" -> " "
|
||||
else -> ""
|
||||
}
|
||||
|
||||
internal val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
|
||||
|
||||
internal fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
|
||||
= toMultiValue(items.asIterable(), collectionFormat, map)
|
||||
|
||||
internal 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))
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
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
|
||||
|
||||
internal open class ApiClient(val baseUrl: String) {
|
||||
internal companion object {
|
||||
protected const val ContentType = "Content-Type"
|
||||
protected const val Accept = "Accept"
|
||||
protected const val Authorization = "Authorization"
|
||||
protected const val JsonMediaType = "application/json"
|
||||
protected const val FormDataMediaType = "multipart/form-data"
|
||||
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||
protected const val XmlMediaType = "application/xml"
|
||||
|
||||
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||
var username: String? = null
|
||||
var password: String? = null
|
||||
var accessToken: String? = null
|
||||
|
||||
@JvmStatic
|
||||
val client: OkHttpClient by lazy {
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||
*
|
||||
* @param file The given file
|
||||
* @return The guessed Content-Type
|
||||
*/
|
||||
protected fun guessContentTypeFromFile(file: File): String {
|
||||
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||
return contentType ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
if (value is File) {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\"; filename=\"${value.name}\""
|
||||
)
|
||||
val fileMediaType = guessContentTypeFromFile(value).toMediaTypeOrNull()
|
||||
addPart(partHeaders, value.asRequestBody(fileMediaType))
|
||||
} else {
|
||||
val partHeaders = Headers.headersOf(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"$key\""
|
||||
)
|
||||
addPart(
|
||||
partHeaders,
|
||||
parameterToString(value).toRequestBody(null)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == FormUrlEncMediaType -> {
|
||||
FormBody.Builder().apply {
|
||||
// content's type *must* be Map<String, Any?>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(content as Map<String, Any?>).forEach { (key, value) ->
|
||||
add(key, parameterToString(value))
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
mediaType == JsonMediaType -> 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.")
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
}
|
||||
val bodyContent = body.string()
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun updateAuthParams(requestConfig: RequestConfig) {
|
||||
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
|
||||
if (apiKey["api_key"] != null) {
|
||||
if (apiKeyPrefix["api_key"] != null) {
|
||||
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
|
||||
} else {
|
||||
requestConfig.headers["api_key"] = apiKey["api_key"]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||
accessToken?.let { accessToken ->
|
||||
requestConfig.headers[Authorization] = "Bearer $accessToken "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
// take authMethod from operation
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
addQueryParameter(query.key, queryValue)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
|
||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||
requestConfig.headers[ContentType] = JsonMediaType
|
||||
}
|
||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||
requestConfig.headers[Accept] = JsonMediaType
|
||||
}
|
||||
val headers = requestConfig.headers
|
||||
|
||||
if(headers[ContentType] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||
}
|
||||
|
||||
if(headers[Accept] ?: "" == "") {
|
||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||
}.apply {
|
||||
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return 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 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.moshi.adapter(T::class.java).toJson(value).replace("\"", "")
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
internal enum class ResponseType {
|
||||
Success, Informational, Redirection, ClientError, ServerError
|
||||
}
|
||||
|
||||
internal interface Response
|
||||
|
||||
internal abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
|
||||
abstract val statusCode: Int
|
||||
abstract val headers: Map<String,List<String>>
|
||||
}
|
||||
|
||||
internal class Success<T>(
|
||||
val data: T,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
): ApiInfrastructureResponse<T>(ResponseType.Success)
|
||||
|
||||
internal class Informational<T>(
|
||||
val statusText: String,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
|
||||
|
||||
internal class Redirection<T>(
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
|
||||
|
||||
internal class ClientError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>> = mapOf()
|
||||
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
|
||||
|
||||
internal class ServerError<T>(
|
||||
val message: String? = null,
|
||||
val body: Any? = null,
|
||||
override val statusCode: Int = -1,
|
||||
override val headers: Map<String, List<String>>
|
||||
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
|
@ -1,29 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
internal object ApplicationDelegates {
|
||||
/**
|
||||
* Provides a property delegate, allowing the property to be set once and only once.
|
||||
*
|
||||
* If unset (no default value), a get on the property will throw [IllegalStateException].
|
||||
*/
|
||||
fun <T> setOnce(defaultValue: T? = null) : ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
|
||||
|
||||
private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
|
||||
private var isSet = false
|
||||
private var value: T? = defaultValue
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value ?: throw IllegalStateException("${property.name} not initialized")
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
|
||||
if (!isSet) {
|
||||
this.value = value
|
||||
isSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
internal class ByteArrayAdapter {
|
||||
@ToJson
|
||||
fun toJson(data: ByteArray): String = String(data)
|
||||
|
||||
@FromJson
|
||||
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
@file:Suppress("unused")
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
internal open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
internal companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
internal open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||
|
||||
internal companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
internal class LocalDateAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDate): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDate {
|
||||
return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
internal class LocalDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: LocalDateTime): String {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): LocalDateTime {
|
||||
return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user