All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openapitools.client.apis.UserApi.kt Maven / Gradle / Ivy

Go to download

A demo for deployment to the Central Repository. A kotlin client library for OpenAPI Petstore by org.openapitools

The newest version!
/**
* 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.*
import io.ktor.client.request.forms.formData
import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.features.json.serializer.KotlinxSerializer
import kotlinx.serialization.json.Json
import io.ktor.http.ParametersBuilder
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

class UserApi(
    baseUrl: String = ApiClient.BASE_URL,
    httpClientEngine: HttpClientEngine? = null,
    jsonSerializer: Json = ApiClient.JSON_DEFAULT
) : ApiClient(baseUrl, httpClientEngine, jsonSerializer) {

    /**
     * Create user
     * This can only be done by the logged in user.
     * @param body Created user object 
     * @return void
     */
    suspend fun createUser(body: User): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = body

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.POST,
            "/user",
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return jsonRequest(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }



    /**
     * Creates list of users with given input array
     * 
     * @param body List of user object 
     * @return void
     */
    suspend fun createUsersWithArrayInput(body: kotlin.collections.List): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = CreateUsersWithArrayInputRequest(body)

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.POST,
            "/user/createWithArray",
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return jsonRequest(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }

    @Serializable
    private class CreateUsersWithArrayInputRequest(val value: List) {
        @Serializer(CreateUsersWithArrayInputRequest::class)
        companion object : KSerializer {
            private val serializer: KSerializer> = serializer>()
            override val descriptor = serializer.descriptor
            override fun serialize(encoder: Encoder, obj: CreateUsersWithArrayInputRequest) = serializer.serialize(encoder, obj.value)
            override fun deserialize(decoder: Decoder) = CreateUsersWithArrayInputRequest(serializer.deserialize(decoder))
        }
    }

    /**
     * Creates list of users with given input array
     * 
     * @param body List of user object 
     * @return void
     */
    suspend fun createUsersWithListInput(body: kotlin.collections.List): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = CreateUsersWithListInputRequest(body)

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.POST,
            "/user/createWithList",
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return jsonRequest(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }

    @Serializable
    private class CreateUsersWithListInputRequest(val value: List) {
        @Serializer(CreateUsersWithListInputRequest::class)
        companion object : KSerializer {
            private val serializer: KSerializer> = serializer>()
            override val descriptor = serializer.descriptor
            override fun serialize(encoder: Encoder, obj: CreateUsersWithListInputRequest) = serializer.serialize(encoder, obj.value)
            override fun deserialize(decoder: Decoder) = CreateUsersWithListInputRequest(serializer.deserialize(decoder))
        }
    }

    /**
     * Delete user
     * This can only be done by the logged in user.
     * @param username The name that needs to be deleted 
     * @return void
     */
    suspend fun deleteUser(username: kotlin.String): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = 
            io.ktor.client.utils.EmptyContent

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.DELETE,
            "/user/{username}".replace("{" + "username" + "}", "$username"),
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return request(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }


    /**
     * Get user by user name
     * 
     * @param username The name that needs to be fetched. Use user1 for testing. 
     * @return User
     */
    @Suppress("UNCHECKED_CAST")
    suspend fun getUserByName(username: kotlin.String): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = 
            io.ktor.client.utils.EmptyContent

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.GET,
            "/user/{username}".replace("{" + "username" + "}", "$username"),
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return request(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }


    /**
     * Logs user into the system
     * 
     * @param username The user name for login 
     * @param password The password for login in clear text 
     * @return kotlin.String
     */
    @Suppress("UNCHECKED_CAST")
    suspend fun loginUser(username: kotlin.String, password: kotlin.String): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = 
            io.ktor.client.utils.EmptyContent

        val localVariableQuery = mutableMapOf>()
        username?.apply { localVariableQuery["username"] = listOf("$username") }
        password?.apply { localVariableQuery["password"] = listOf("$password") }

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.GET,
            "/user/login",
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return request(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }


    /**
     * Logs out current logged in user session
     * 
     * @return void
     */
    suspend fun logoutUser(): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = 
            io.ktor.client.utils.EmptyContent

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.GET,
            "/user/logout",
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return request(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }


    /**
     * 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
     */
    suspend fun updateUser(username: kotlin.String, body: User): HttpResponse {

        val localVariableAuthNames = listOf()

        val localVariableBody = body

        val localVariableQuery = mutableMapOf>()

        val localVariableHeaders = mutableMapOf()

        val localVariableConfig = RequestConfig(
            RequestMethod.PUT,
            "/user/{username}".replace("{" + "username" + "}", "$username"),
            query = localVariableQuery,
            headers = localVariableHeaders
        )

        return jsonRequest(
            localVariableConfig,
            localVariableBody,
            localVariableAuthNames
        ).wrap()
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy