[kotlin][client] rename ApiInfrastructureResponse to ApiResponse (#11094)

* rename ApiInfrastructureResponse to ApiResponse

* mark ApiResponse as reserved word

* update samples, docs

* fix typo
This commit is contained in:
William Cheng
2021-12-12 16:32:08 +08:00
committed by GitHub
parent 3247903caa
commit fbb61658df
163 changed files with 1076 additions and 1025 deletions

View File

@@ -22,11 +22,11 @@ package org.openapitools.client.apis
import java.io.IOException
import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.ModelApiResponse
import org.openapitools.client.models.Pet
import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ApiInfrastructureResponse
import org.openapitools.client.infrastructure.ApiResponse
import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError
import org.openapitools.client.infrastructure.ServerException
@@ -80,12 +80,12 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun addPetWithHttpInfo(body: Pet) : ApiInfrastructureResponse<Unit?> {
fun addPetWithHttpInfo(body: Pet) : ApiResponse<Unit?> {
val localVariableConfig = addPetRequestConfig(body = body)
return request<Pet, Unit>(
@@ -150,12 +150,12 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*
* @param petId Pet id to delete
* @param apiKey (optional)
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun deletePetWithHttpInfo(petId: kotlin.Long, apiKey: kotlin.String?) : ApiInfrastructureResponse<Unit?> {
fun deletePetWithHttpInfo(petId: kotlin.Long, apiKey: kotlin.String?) : ApiResponse<Unit?> {
val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey)
return request<Unit, Unit>(
@@ -222,14 +222,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* 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 ApiInfrastructureResponse<kotlin.collections.List<Pet>?>
* @return ApiResponse<kotlin.collections.List<Pet>?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
@Deprecated(message = "This operation is deprecated.")
fun findPetsByTagsWithHttpInfo(tags: kotlin.collections.List<kotlin.String>) : ApiInfrastructureResponse<kotlin.collections.List<Pet>?> {
fun findPetsByTagsWithHttpInfo(tags: kotlin.collections.List<kotlin.String>) : ApiResponse<kotlin.collections.List<Pet>?> {
@Suppress("DEPRECATION")
val localVariableConfig = findPetsByTagsRequestConfig(tags = tags)
@@ -298,13 +298,13 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Get all pets
*
* @param lastUpdated When this endpoint was hit last to help identify if the client already has the latest copy. (optional)
* @return ApiInfrastructureResponse<kotlin.collections.List<Pet>?>
* @return ApiResponse<kotlin.collections.List<Pet>?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getAllPetsWithHttpInfo(lastUpdated: java.time.OffsetDateTime?) : ApiInfrastructureResponse<kotlin.collections.List<Pet>?> {
fun getAllPetsWithHttpInfo(lastUpdated: java.time.OffsetDateTime?) : ApiResponse<kotlin.collections.List<Pet>?> {
val localVariableConfig = getAllPetsRequestConfig(lastUpdated = lastUpdated)
return request<Unit, kotlin.collections.List<Pet>>(
@@ -373,13 +373,13 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Find pet by ID
* Returns a single pet
* @param petId ID of pet to return
* @return ApiInfrastructureResponse<Pet?>
* @return ApiResponse<Pet?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getPetByIdWithHttpInfo(petId: kotlin.Long) : ApiInfrastructureResponse<Pet?> {
fun getPetByIdWithHttpInfo(petId: kotlin.Long) : ApiResponse<Pet?> {
val localVariableConfig = getPetByIdRequestConfig(petId = petId)
return request<Unit, Pet>(
@@ -442,12 +442,12 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun updatePetWithHttpInfo(body: Pet) : ApiInfrastructureResponse<Unit?> {
fun updatePetWithHttpInfo(body: Pet) : ApiResponse<Unit?> {
val localVariableConfig = updatePetRequestConfig(body = body)
return request<Pet, Unit>(
@@ -514,12 +514,12 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @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 ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun updatePetWithFormWithHttpInfo(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : ApiInfrastructureResponse<Unit?> {
fun updatePetWithFormWithHttpInfo(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : ApiResponse<Unit?> {
val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status)
return request<Map<String, Any?>, Unit>(
@@ -555,7 +555,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server (optional)
* @param file file to upload (optional)
* @return ApiResponse
* @return ModelApiResponse
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
* @throws UnsupportedOperationException If the API returns an informational or redirection response
@@ -564,11 +564,11 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse {
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ModelApiResponse {
val localVarResponse = uploadFileWithHttpInfo(petId = petId, additionalMetadata = additionalMetadata, file = file)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ApiResponse
ResponseType.Success -> (localVarResponse as Success<*>).data as ModelApiResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
@@ -588,16 +588,16 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server (optional)
* @param file file to upload (optional)
* @return ApiInfrastructureResponse<ApiResponse?>
* @return ApiResponse<ModelApiResponse?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun uploadFileWithHttpInfo(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiInfrastructureResponse<ApiResponse?> {
fun uploadFileWithHttpInfo(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse<ModelApiResponse?> {
val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file)
return request<Map<String, Any?>, ApiResponse>(
return request<Map<String, Any?>, ModelApiResponse>(
localVariableConfig
)
}

View File

@@ -25,7 +25,7 @@ import java.io.IOException
import org.openapitools.client.models.Order
import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ApiInfrastructureResponse
import org.openapitools.client.infrastructure.ApiResponse
import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError
import org.openapitools.client.infrastructure.ServerException
@@ -79,12 +79,12 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* @param orderId ID of the order that needs to be deleted
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun deleteOrderWithHttpInfo(orderId: kotlin.String) : ApiInfrastructureResponse<Unit?> {
fun deleteOrderWithHttpInfo(orderId: kotlin.String) : ApiResponse<Unit?> {
val localVariableConfig = deleteOrderRequestConfig(orderId = orderId)
return request<Unit, Unit>(
@@ -145,13 +145,13 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
* @return ApiInfrastructureResponse<kotlin.collections.Map<kotlin.String, kotlin.Int>?>
* @return ApiResponse<kotlin.collections.Map<kotlin.String, kotlin.Int>?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getInventoryWithHttpInfo() : ApiInfrastructureResponse<kotlin.collections.Map<kotlin.String, kotlin.Int>?> {
fun getInventoryWithHttpInfo() : ApiResponse<kotlin.collections.Map<kotlin.String, kotlin.Int>?> {
val localVariableConfig = getInventoryRequestConfig()
return request<Unit, kotlin.collections.Map<kotlin.String, kotlin.Int>>(
@@ -214,13 +214,13 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
* Find purchase order by ID
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched
* @return ApiInfrastructureResponse<Order?>
* @return ApiResponse<Order?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getOrderByIdWithHttpInfo(orderId: kotlin.Long) : ApiInfrastructureResponse<Order?> {
fun getOrderByIdWithHttpInfo(orderId: kotlin.Long) : ApiResponse<Order?> {
val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId)
return request<Unit, Order>(
@@ -284,13 +284,13 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath)
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @return ApiInfrastructureResponse<Order?>
* @return ApiResponse<Order?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun placeOrderWithHttpInfo(body: Order) : ApiInfrastructureResponse<Order?> {
fun placeOrderWithHttpInfo(body: Order) : ApiResponse<Order?> {
val localVariableConfig = placeOrderRequestConfig(body = body)
return request<Order, Order>(

View File

@@ -25,7 +25,7 @@ import java.io.IOException
import org.openapitools.client.models.User
import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ApiInfrastructureResponse
import org.openapitools.client.infrastructure.ApiResponse
import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError
import org.openapitools.client.infrastructure.ServerException
@@ -79,12 +79,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Create user
* This can only be done by the logged in user.
* @param body Created user object
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun createUserWithHttpInfo(body: User) : ApiInfrastructureResponse<Unit?> {
fun createUserWithHttpInfo(body: User) : ApiResponse<Unit?> {
val localVariableConfig = createUserRequestConfig(body = body)
return request<User, Unit>(
@@ -146,12 +146,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Creates list of users with given input array
*
* @param body List of user object
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun createUsersWithArrayInputWithHttpInfo(body: kotlin.collections.List<User>) : ApiInfrastructureResponse<Unit?> {
fun createUsersWithArrayInputWithHttpInfo(body: kotlin.collections.List<User>) : ApiResponse<Unit?> {
val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body)
return request<kotlin.collections.List<User>, Unit>(
@@ -213,12 +213,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Creates list of users with given input array
*
* @param body List of user object
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun createUsersWithListInputWithHttpInfo(body: kotlin.collections.List<User>) : ApiInfrastructureResponse<Unit?> {
fun createUsersWithListInputWithHttpInfo(body: kotlin.collections.List<User>) : ApiResponse<Unit?> {
val localVariableConfig = createUsersWithListInputRequestConfig(body = body)
return request<kotlin.collections.List<User>, Unit>(
@@ -280,12 +280,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Delete user
* This can only be done by the logged in user.
* @param username The name that needs to be deleted
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun deleteUserWithHttpInfo(username: kotlin.String) : ApiInfrastructureResponse<Unit?> {
fun deleteUserWithHttpInfo(username: kotlin.String) : ApiResponse<Unit?> {
val localVariableConfig = deleteUserRequestConfig(username = username)
return request<Unit, Unit>(
@@ -348,13 +348,13 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @return ApiInfrastructureResponse<User?>
* @return ApiResponse<User?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getUserByNameWithHttpInfo(username: kotlin.String) : ApiInfrastructureResponse<User?> {
fun getUserByNameWithHttpInfo(username: kotlin.String) : ApiResponse<User?> {
val localVariableConfig = getUserByNameRequestConfig(username = username)
return request<Unit, User>(
@@ -420,13 +420,13 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
*
* @param username The user name for login
* @param password The password for login in clear text
* @return ApiInfrastructureResponse<kotlin.String?>
* @return ApiResponse<kotlin.String?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun loginUserWithHttpInfo(username: kotlin.String, password: kotlin.String) : ApiInfrastructureResponse<kotlin.String?> {
fun loginUserWithHttpInfo(username: kotlin.String, password: kotlin.String) : ApiResponse<kotlin.String?> {
val localVariableConfig = loginUserRequestConfig(username = username, password = password)
return request<Unit, kotlin.String>(
@@ -492,12 +492,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
/**
* Logs out current logged in user session
*
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun logoutUserWithHttpInfo() : ApiInfrastructureResponse<Unit?> {
fun logoutUserWithHttpInfo() : ApiResponse<Unit?> {
val localVariableConfig = logoutUserRequestConfig()
return request<Unit, Unit>(
@@ -560,12 +560,12 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
* This can only be done by the logged in user.
* @param username name that need to be deleted
* @param body Updated user object
* @return ApiInfrastructureResponse<Unit?>
* @return ApiResponse<Unit?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Throws(IllegalStateException::class, IOException::class)
fun updateUserWithHttpInfo(username: kotlin.String, body: User) : ApiInfrastructureResponse<Unit?> {
fun updateUserWithHttpInfo(username: kotlin.String, body: User) : ApiResponse<Unit?> {
val localVariableConfig = updateUserRequestConfig(username = username, body = body)
return request<User, Unit>(

View File

@@ -167,7 +167,7 @@ open class ApiClient(val baseUrl: String) {
}
}
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiInfrastructureResponse<T?> {
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiResponse<T?> {
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
// take authMethod from operation

View File

@@ -6,7 +6,7 @@ enum class ResponseType {
interface Response
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
abstract class ApiResponse<T>(val responseType: ResponseType): Response {
abstract val statusCode: Int
abstract val headers: Map<String,List<String>>
}
@@ -15,29 +15,29 @@ class Success<T>(
val data: T,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
): ApiInfrastructureResponse<T>(ResponseType.Success)
): ApiResponse<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)
) : ApiResponse<T>(ResponseType.Informational)
class Redirection<T>(
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
) : ApiResponse<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)
) : ApiResponse<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)
): ApiResponse<T>(ResponseType.ServerError)

View File

@@ -34,7 +34,7 @@ import kotlinx.parcelize.Parcelize
*/
@Parcelize
data class ApiResponse (
data class ModelApiResponse (
@Json(name = "code")
val code: kotlin.Int? = null,