[kotlin][client] define kotlin coroutines context (#9936)

* [kotlin][client] define coroutines context

* [kotlin][client] update sample projects

* [kotlin][client] add missing kotlinx coroutines dependency

* [kotlin][client] update sample projects
This commit is contained in:
Bruno Coelho 2021-07-13 08:26:59 +01:00 committed by GitHub
parent 7573234a4c
commit 26f998b043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 42 deletions

View File

@ -53,6 +53,11 @@ test {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
{{^doNotUseRxAndCoroutines}}
{{#useCoroutines}}
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1"
{{/useCoroutines}}
{{/doNotUseRxAndCoroutines}}
{{#moshi}} {{#moshi}}
{{^moshiCodeGen}} {{^moshiCodeGen}}
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

View File

@ -4,6 +4,12 @@ package {{apiPackage}}
{{#imports}}import {{import}} {{#imports}}import {{import}}
{{/imports}} {{/imports}}
{{^doNotUseRxAndCoroutines}}
{{#useCoroutines}}
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
{{/useCoroutines}}
{{/doNotUseRxAndCoroutines}}
import {{packageName}}.infrastructure.ApiClient import {{packageName}}.infrastructure.ApiClient
import {{packageName}}.infrastructure.ClientException import {{packageName}}.infrastructure.ClientException
import {{packageName}}.infrastructure.ClientError import {{packageName}}.infrastructure.ClientError
@ -40,7 +46,7 @@ import {{packageName}}.infrastructure.toMultiValue
{{#isDeprecated}} {{#isDeprecated}}
@Deprecated(message = "This operation is deprecated.") @Deprecated(message = "This operation is deprecated.")
{{/isDeprecated}} {{/isDeprecated}}
{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}} { {{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{^doNotUseRxAndCoroutines}}{{#useCoroutines}} = withContext(Dispatchers.IO){{/useCoroutines}}{{/doNotUseRxAndCoroutines}} {
{{#isDeprecated}} {{#isDeprecated}}
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
{{/isDeprecated}} {{/isDeprecated}}
@ -50,7 +56,7 @@ import {{packageName}}.infrastructure.toMultiValue
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}@withContext{{/useCoroutines}}{{/doNotUseRxAndCoroutines}} when (localVarResponse.responseType) {
ResponseType.Success -> {{#returnType}}(localVarResponse as Success<*>).data as {{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}} ResponseType.Success -> {{#returnType}}(localVarResponse as Success<*>).data as {{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")

View File

@ -29,6 +29,7 @@ test {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1"
implementation "com.google.code.gson:gson:2.8.7" implementation "com.google.code.gson:gson:2.8.7"
implementation "com.squareup.okhttp3:okhttp:4.9.1" implementation "com.squareup.okhttp3:okhttp:4.9.1"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"

View File

@ -14,6 +14,8 @@ package org.openapitools.client.apis
import org.openapitools.client.models.ApiResponse import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.Pet import org.openapitools.client.models.Pet
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.openapitools.client.infrastructure.ApiClient import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ClientException import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError import org.openapitools.client.infrastructure.ClientError
@ -44,14 +46,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun addPet(body: Pet) : Unit { suspend fun addPet(body: Pet) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = addPetRequestConfig(body = body) val localVariableConfig = addPetRequestConfig(body = body)
val localVarResponse = request<Pet, Unit>( val localVarResponse = request<Pet, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -97,14 +99,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey)
val localVarResponse = request<Unit, Unit>( val localVarResponse = request<Unit, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -152,14 +154,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> { suspend fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> = withContext(Dispatchers.IO) {
val localVariableConfig = findPetsByStatusRequestConfig(status = status) val localVariableConfig = findPetsByStatusRequestConfig(status = status)
val localVarResponse = request<Unit, kotlin.collections.List<Pet>>( val localVarResponse = request<Unit, kotlin.collections.List<Pet>>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet> ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -209,7 +211,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
@Deprecated(message = "This operation is deprecated.") @Deprecated(message = "This operation is deprecated.")
suspend fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> { suspend fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> = withContext(Dispatchers.IO) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) val localVariableConfig = findPetsByTagsRequestConfig(tags = tags)
@ -217,7 +219,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet> ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List<Pet>
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -267,14 +269,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun getPetById(petId: kotlin.Long) : Pet { suspend fun getPetById(petId: kotlin.Long) : Pet = withContext(Dispatchers.IO) {
val localVariableConfig = getPetByIdRequestConfig(petId = petId) val localVariableConfig = getPetByIdRequestConfig(petId = petId)
val localVarResponse = request<Unit, Pet>( val localVarResponse = request<Unit, Pet>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as Pet ResponseType.Success -> (localVarResponse as Success<*>).data as Pet
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -319,14 +321,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun updatePet(body: Pet) : Unit { suspend fun updatePet(body: Pet) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = updatePetRequestConfig(body = body) val localVariableConfig = updatePetRequestConfig(body = body)
val localVarResponse = request<Pet, Unit>( val localVarResponse = request<Pet, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -373,14 +375,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status)
val localVarResponse = request<Map<String, Any?>, Unit>( val localVarResponse = request<Map<String, Any?>, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -430,14 +432,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse = withContext(Dispatchers.IO) {
val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file)
val localVarResponse = request<Map<String, Any?>, ApiResponse>( val localVarResponse = request<Map<String, Any?>, ApiResponse>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")

View File

@ -13,6 +13,8 @@ package org.openapitools.client.apis
import org.openapitools.client.models.Order import org.openapitools.client.models.Order
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.openapitools.client.infrastructure.ApiClient import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ClientException import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError import org.openapitools.client.infrastructure.ClientError
@ -43,14 +45,14 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun deleteOrder(orderId: kotlin.String) : Unit { suspend fun deleteOrder(orderId: kotlin.String) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) val localVariableConfig = deleteOrderRequestConfig(orderId = orderId)
val localVarResponse = request<Unit, Unit>( val localVarResponse = request<Unit, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -95,14 +97,14 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> { suspend fun getInventory() : kotlin.collections.Map<kotlin.String, kotlin.Int> = withContext(Dispatchers.IO) {
val localVariableConfig = getInventoryRequestConfig() val localVariableConfig = getInventoryRequestConfig()
val localVarResponse = request<Unit, kotlin.collections.Map<kotlin.String, kotlin.Int>>( val localVarResponse = request<Unit, kotlin.collections.Map<kotlin.String, kotlin.Int>>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int> 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.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -147,14 +149,14 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun getOrderById(orderId: kotlin.Long) : Order { suspend fun getOrderById(orderId: kotlin.Long) : Order = withContext(Dispatchers.IO) {
val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId)
val localVarResponse = request<Unit, Order>( val localVarResponse = request<Unit, Order>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as Order ResponseType.Success -> (localVarResponse as Success<*>).data as Order
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -200,14 +202,14 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun placeOrder(body: Order) : Order { suspend fun placeOrder(body: Order) : Order = withContext(Dispatchers.IO) {
val localVariableConfig = placeOrderRequestConfig(body = body) val localVariableConfig = placeOrderRequestConfig(body = body)
val localVarResponse = request<Order, Order>( val localVarResponse = request<Order, Order>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as Order ResponseType.Success -> (localVarResponse as Success<*>).data as Order
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")

View File

@ -13,6 +13,8 @@ package org.openapitools.client.apis
import org.openapitools.client.models.User import org.openapitools.client.models.User
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.openapitools.client.infrastructure.ApiClient import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ClientException import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError import org.openapitools.client.infrastructure.ClientError
@ -43,14 +45,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun createUser(body: User) : Unit { suspend fun createUser(body: User) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = createUserRequestConfig(body = body) val localVariableConfig = createUserRequestConfig(body = body)
val localVarResponse = request<User, Unit>( val localVarResponse = request<User, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -95,14 +97,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit { suspend fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body)
val localVarResponse = request<kotlin.collections.List<User>, Unit>( val localVarResponse = request<kotlin.collections.List<User>, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -147,14 +149,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit { suspend fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = createUsersWithListInputRequestConfig(body = body) val localVariableConfig = createUsersWithListInputRequestConfig(body = body)
val localVarResponse = request<kotlin.collections.List<User>, Unit>( val localVarResponse = request<kotlin.collections.List<User>, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -199,14 +201,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun deleteUser(username: kotlin.String) : Unit { suspend fun deleteUser(username: kotlin.String) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = deleteUserRequestConfig(username = username) val localVariableConfig = deleteUserRequestConfig(username = username)
val localVarResponse = request<Unit, Unit>( val localVarResponse = request<Unit, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -252,14 +254,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun getUserByName(username: kotlin.String) : User { suspend fun getUserByName(username: kotlin.String) : User = withContext(Dispatchers.IO) {
val localVariableConfig = getUserByNameRequestConfig(username = username) val localVariableConfig = getUserByNameRequestConfig(username = username)
val localVarResponse = request<Unit, User>( val localVarResponse = request<Unit, User>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as User ResponseType.Success -> (localVarResponse as Success<*>).data as User
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -306,14 +308,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String { suspend fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String = withContext(Dispatchers.IO) {
val localVariableConfig = loginUserRequestConfig(username = username, password = password) val localVariableConfig = loginUserRequestConfig(username = username, password = password)
val localVarResponse = request<Unit, kotlin.String>( val localVarResponse = request<Unit, kotlin.String>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.String
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -362,14 +364,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun logoutUser() : Unit { suspend fun logoutUser() : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = logoutUserRequestConfig() val localVariableConfig = logoutUserRequestConfig()
val localVarResponse = request<Unit, Unit>( val localVarResponse = request<Unit, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
@ -414,14 +416,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @throws ServerException If the API returns a server error response * @throws ServerException If the API returns a server error response
*/ */
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
suspend fun updateUser(username: kotlin.String, body: User) : Unit { suspend fun updateUser(username: kotlin.String, body: User) : Unit = withContext(Dispatchers.IO) {
val localVariableConfig = updateUserRequestConfig(username = username, body = body) val localVariableConfig = updateUserRequestConfig(username = username, body = body)
val localVarResponse = request<User, Unit>( val localVarResponse = request<User, Unit>(
localVariableConfig localVariableConfig
) )
return when (localVarResponse.responseType) { return@withContext when (localVarResponse.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")