diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache index 435583e9726..61677c22aff 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache @@ -12,5 +12,6 @@ package {{packageName}}.infrastructure val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache index 13c9c560407..8adf1980e42 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache @@ -41,6 +41,37 @@ import {{packageName}}.infrastructure.toMultiValue @Deprecated(message = "This operation is deprecated.") {{/isDeprecated}} {{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}} { + val localVariableConfig = {{operationId}}RequestConfig({{#allParams}}{{{paramName}}} = {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}) + + val localVarResponse = request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Any?{{/returnType}}>( + localVariableConfig + ) + + return when (localVarResponse.responseType) { + 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.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) + } + } + } + + /** + * To obtain the request config of the operation {{operationId}} + * + {{#allParams}}* @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + {{/allParams}}* @return RequestConfig + */ + {{#isDeprecated}} + @Deprecated(message = "This operation is deprecated.") + {{/isDeprecated}} + fun {{operationId}}RequestConfig({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : RequestConfig { val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{{paramName}}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to {{{paramName}}}{{^-last}}, {{/-last}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}} val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mutableMapOf() {{/hasQueryParams}}{{#hasQueryParams}}mutableMapOf>() @@ -68,30 +99,16 @@ import {{packageName}}.infrastructure.toMultiValue {{#headerParams}} {{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} } {{/headerParams}} + val localVariableConfig = RequestConfig( - RequestMethod.{{httpMethod}}, - "{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", "${{{paramName}}}"){{/pathParams}}, + method = RequestMethod.{{httpMethod}}, + path = "{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", "${{{paramName}}}"){{/pathParams}}, query = localVariableQuery, - headers = localVariableHeaders - ) - val localVarResponse = request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Any?{{/returnType}}>( - localVariableConfig, - localVariableBody + headers = localVariableHeaders, + body = localVariableBody ) - return when (localVarResponse.responseType) { - 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.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) - } - } + return localVariableConfig } {{/operation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 3bff3d10d97..cfc573b9f82 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -232,7 +232,7 @@ import org.threeten.bp.OffsetTime } {{/hasAuthMethods}} - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { {{#jvm-okhttp3}} val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.") {{/jvm-okhttp3}} @@ -276,12 +276,12 @@ import org.threeten.bp.OffsetTime val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5d64a9add42..bcbb1cf8627 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2c15d73b189..637ca64c247 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 6685f0a73d4..d939e3d5a43 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -129,21 +158,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -161,6 +179,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get all pets * @@ -173,23 +217,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getAllPets(lastUpdated: java.time.OffsetDateTime?) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - if (lastUpdated != null) { - put("lastUpdated", listOf(parseDateToQueryString(lastUpdated))) - } - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/getAll", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getAllPetsRequestConfig(lastUpdated = lastUpdated) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -207,6 +238,33 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getAllPets + * + * @param lastUpdated When this endpoint was hit last to help indentify if the client already has the latest copy. (optional) + * @return RequestConfig + */ + fun getAllPetsRequestConfig(lastUpdated: java.time.OffsetDateTime?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + if (lastUpdated != null) { + put("lastUpdated", listOf(parseDateToQueryString(lastUpdated))) + } + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/getAll", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -219,18 +277,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -248,6 +298,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -259,18 +331,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -288,6 +352,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -301,18 +387,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -330,6 +408,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -344,18 +446,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -373,4 +467,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a69de1961da..e1d5bc9c412 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1ca2057e217..78223583f64 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") suspend fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun getPetById(petId: kotlin.Long) : Pet { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend 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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend 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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index deb7ba6cf49..4ab794d6608 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun deleteOrder(orderId: kotlin.String) : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun getOrderById(orderId: kotlin.Long) : Order { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun placeOrder(body: Order) : Order { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6494674c7f3..911bbee5b6b 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun deleteUser(username: kotlin.String) : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun getUserByName(username: kotlin.String) : User { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) suspend fun updateUser(username: kotlin.String, body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5d64a9add42..bcbb1cf8627 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e7f366d02cd..7a8dcc91cd4 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 69cb6b35ef2..b6b38fa42f3 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 4f8898adf9b..19b7acdbd31 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(b } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 725b36b0106..979bb1b81f8 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 473b3fd42ce..c4da8e3989b 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ internal open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ internal open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 3e87d2c30f9..68f41c5497d 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ internal data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index ef80c520fd2..95f695cb9f4 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List? { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List? { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index b9dd7b38f59..c442f866100 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map? { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 2ae5998489d..6e6c329144c 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e7f366d02cd..7a8dcc91cd4 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f60e40309bc..9d526273d7a 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -135,7 +135,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -172,12 +172,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index da9784198d1..4fbeccdbc00 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun deletePet(apiKey: kotlin.String?, petId: kotlin.Long) : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(apiKey = apiKey, petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param apiKey (optional) + * @param petId Pet id to delete + * @return RequestConfig + */ + fun deletePetRequestConfig(apiKey: kotlin.String?, petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e7f366d02cd..7a8dcc91cd4 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cb540f6ebd7..135bcdc790e 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e4f7f4eeae0..c8b93b33bf6 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -45,18 +45,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun addPet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = addPetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -74,6 +66,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation addPet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun addPetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Deletes a pet * @@ -86,19 +100,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deletePetRequestConfig(petId = petId, apiKey = apiKey) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -116,6 +121,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deletePet + * + * @param petId Pet id to delete + * @param apiKey (optional) + * @return RequestConfig + */ + fun deletePetRequestConfig(petId: kotlin.Long, apiKey: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -128,21 +157,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("status", toMultiValue(status.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByStatus", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByStatusRequestConfig(status = status) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -160,6 +178,31 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByStatus + * + * @param status Status values that need to be considered for filter + * @return RequestConfig + */ + fun findPetsByStatusRequestConfig(status: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByStatus", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -173,21 +216,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) @Deprecated(message = "This operation is deprecated.") fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - put("tags", toMultiValue(tags.toList(), "csv")) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/findByTags", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = findPetsByTagsRequestConfig(tags = tags) + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -205,6 +237,32 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation findPetsByTags + * + * @param tags Tags to filter by + * @return RequestConfig + */ + @Deprecated(message = "This operation is deprecated.") + fun findPetsByTagsRequestConfig(tags: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/findByTags", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find pet by ID * Returns a single pet @@ -217,18 +275,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getPetByIdRequestConfig(petId = petId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -246,6 +296,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getPetById + * + * @param petId ID of pet to return + * @return RequestConfig + */ + fun getPetByIdRequestConfig(petId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Update an existing pet * @@ -257,18 +329,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun updatePet(body: Pet) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/pet", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -286,6 +350,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePet + * + * @param body Pet object that needs to be added to the store + * @return RequestConfig + */ + fun updatePetRequestConfig(body: Pet) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/pet", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updates a pet in the store with form data * @@ -299,18 +385,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updatePetWithFormRequestConfig(petId = petId, name = name, status = status) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -328,6 +406,30 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updatePetWithForm + * + * @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 RequestConfig + */ + fun updatePetWithFormRequestConfig(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * uploads an image * @@ -342,18 +444,10 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf("Content-Type" to "multipart/form-data") - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = uploadFileRequestConfig(petId = petId, additionalMetadata = additionalMetadata, file = file) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -371,4 +465,28 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation uploadFile + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return RequestConfig + */ + fun uploadFileRequestConfig(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : RequestConfig { + val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file) + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", "$petId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 08822c67e32..215ed63420c 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -44,18 +44,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteOrderRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation deleteOrder + * + * @param orderId ID of the order that needs to be deleted + * @return RequestConfig + */ + fun deleteOrderRequestConfig(orderId: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -84,18 +98,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getInventory() : kotlin.collections.Map { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/inventory", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getInventoryRequestConfig() + val localVarResponse = request>( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,27 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getInventory + * + * @return RequestConfig + */ + fun getInventoryRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/inventory", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -125,18 +152,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getOrderByIdRequestConfig(orderId = orderId) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -154,6 +173,28 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation getOrderById + * + * @param orderId ID of pet that needs to be fetched + * @return RequestConfig + */ + fun getOrderByIdRequestConfig(orderId: kotlin.Long) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/store/order/{orderId}".replace("{"+"orderId"+"}", "$orderId"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Place an order for a pet * @@ -166,18 +207,10 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/store/order", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = placeOrderRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -195,4 +228,26 @@ class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) } } + /** + * To obtain the request config of the operation placeOrder + * + * @param body order placed for purchasing the pet + * @return RequestConfig + */ + fun placeOrderRequestConfig(body: Order) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/store/order", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 258a2540e9e..53748b93463 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -44,18 +44,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUser(body: User) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUserRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -73,6 +65,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUser + * + * @param body Created user object + * @return RequestConfig + */ + fun createUserRequestConfig(body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -84,18 +98,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithArray", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithArrayInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -113,6 +119,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithArrayInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithArrayInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithArray", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Creates list of users with given input array * @@ -124,18 +152,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun createUsersWithListInput(body: kotlin.collections.List) : Unit { - val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.POST, - "/user/createWithList", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = createUsersWithListInputRequestConfig(body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -153,6 +173,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation createUsersWithListInput + * + * @param body List of user object + * @return RequestConfig + */ + fun createUsersWithListInputRequestConfig(body: kotlin.collections.List) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.POST, + path = "/user/createWithList", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Delete user * This can only be done by the logged in user. @@ -164,18 +206,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.DELETE, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = deleteUserRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -193,6 +227,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation deleteUser + * + * @param username The name that needs to be deleted + * @return RequestConfig + */ + fun deleteUserRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.DELETE, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Get user by user name * @@ -205,18 +261,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = getUserByNameRequestConfig(username = username) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -234,6 +282,28 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation getUserByName + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return RequestConfig + */ + fun getUserByNameRequestConfig(username: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs user into the system * @@ -247,22 +317,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @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>() - .apply { - put("username", listOf(username.toString())) - put("password", listOf(password.toString())) - } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/login", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = loginUserRequestConfig(username = username, password = password) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -280,6 +338,33 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation loginUser + * + * @param username The user name for login + * @param password The password for login in clear text + * @return RequestConfig + */ + fun loginUserRequestConfig(username: kotlin.String, password: kotlin.String) : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/login", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Logs out current logged in user session * @@ -290,18 +375,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun logoutUser() : Unit { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf() - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/user/logout", - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = logoutUserRequestConfig() + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -319,6 +396,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation logoutUser + * + * @return RequestConfig + */ + fun logoutUserRequestConfig() : RequestConfig { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.GET, + path = "/user/logout", + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + /** * Updated user * This can only be done by the logged in user. @@ -331,18 +429,10 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { */ @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 = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.PUT, - "/user/{username}".replace("{"+"username"+"}", "$username"), - query = localVariableQuery, - headers = localVariableHeaders - ) + val localVariableConfig = updateUserRequestConfig(username = username, body = body) + val localVarResponse = request( - localVariableConfig, - localVariableBody + localVariableConfig ) return when (localVarResponse.responseType) { @@ -360,4 +450,27 @@ class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { } } + /** + * To obtain the request config of the operation updateUser + * + * @param username name that need to be deleted + * @param body Updated user object + * @return RequestConfig + */ + fun updateUserRequestConfig(username: kotlin.String, body: User) : RequestConfig { + val localVariableBody: kotlin.Any? = body + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + + val localVariableConfig = RequestConfig( + method = RequestMethod.PUT, + path = "/user/{username}".replace("{"+"username"+"}", "$username"), + query = localVariableQuery, + headers = localVariableHeaders, + body = localVariableBody + ) + + return localVariableConfig + } + } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e7f366d02cd..7a8dcc91cd4 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -137,7 +137,7 @@ open class ApiClient(val baseUrl: String) { } } - protected inline fun request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse { + protected inline fun request(requestConfig: RequestConfig): ApiInfrastructureResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -174,12 +174,12 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.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.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) }.apply { headers.forEach { header -> addHeader(header.key, header.value) } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 9c22257e223..0f2790f370e 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,6 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: MutableMap> = mutableMapOf() + val query: MutableMap> = mutableMapOf(), + val body: kotlin.Any? = null ) \ No newline at end of file