Fix null assignation to header/query param map (#3749)

Also regenerates the clients
This commit is contained in:
Armand Mégrot
2019-08-24 17:09:57 +02:00
committed by William Cheng
parent dfb4c133d8
commit 1f5aa22f5c
21 changed files with 253 additions and 134 deletions

View File

@@ -82,20 +82,22 @@ open class ApiClient(val baseUrl: String) {
{{#isKeyInQuery}} {{#isKeyInQuery}}
if (requestConfig.query["{{keyParamName}}"].isNullOrEmpty()) { if (requestConfig.query["{{keyParamName}}"].isNullOrEmpty()) {
{{/isKeyInQuery}} {{/isKeyInQuery}}
if (apiKeyPrefix["{{keyParamName}}"] != null) { if (apiKey["{{keyParamName}}"] != null) {
{{#isKeyInHeader}} if (apiKeyPrefix["{{keyParamName}}"] != null) {
requestConfig.headers["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"] + " " + apiKey["{{keyParamName}}"] {{#isKeyInHeader}}
{{/isKeyInHeader}} requestConfig.headers["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"]!! + " " + apiKey["{{keyParamName}}"]!!
{{#isKeyInQuery}} {{/isKeyInHeader}}
requestConfig.query["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"] + " " + apiKey["{{keyParamName}}"] {{#isKeyInQuery}}
{{/isKeyInQuery}} requestConfig.query["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"]!! + " " + apiKey["{{keyParamName}}"]!!
} else { {{/isKeyInQuery}}
{{#isKeyInHeader}} } else {
requestConfig.headers["{{keyParamName}}"] = apiKey["{{keyParamName}}"] {{#isKeyInHeader}}
{{/isKeyInHeader}} requestConfig.headers["{{keyParamName}}"] = apiKey["{{keyParamName}}"]!!
{{#isKeyInQuery}} {{/isKeyInHeader}}
requestConfig.query["{{keyParamName}}"] = apiKey["{{keyParamName}}"] {{#isKeyInQuery}}
{{/isKeyInQuery}} requestConfig.query["{{keyParamName}}"] = apiKey["{{keyParamName}}"]!!
{{/isKeyInQuery}}
}
} }
} }
{{/isApiKey}} {{/isApiKey}}

View File

@@ -74,10 +74,12 @@ open class ApiClient(val baseUrl: String) {
protected fun updateAuthParams(requestConfig: RequestConfig) { protected fun updateAuthParams(requestConfig: RequestConfig) {
if (requestConfig.headers["api_key"].isNullOrEmpty()) { if (requestConfig.headers["api_key"].isNullOrEmpty()) {
if (apiKeyPrefix["api_key"] != null) { if (apiKey["api_key"] != null) {
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"] + " " + apiKey["api_key"] if (apiKeyPrefix["api_key"] != null) {
} else { requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
requestConfig.headers["api_key"] = apiKey["api_key"] } else {
requestConfig.headers["api_key"] = apiKey["api_key"]!!
}
} }
} }
if (requestConfig.headers[Authorization].isNullOrEmpty()) { if (requestConfig.headers[Authorization].isNullOrEmpty()) {

View File

@@ -1 +1 @@
4.1.0-SNAPSHOT 4.1.1-SNAPSHOT

View File

@@ -17,6 +17,7 @@ Method | HTTP request | Description
[**testGroupParameters**](FakeApi.md#testGroupParameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional) [**testGroupParameters**](FakeApi.md#testGroupParameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
[**testInlineAdditionalProperties**](FakeApi.md#testInlineAdditionalProperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties [**testInlineAdditionalProperties**](FakeApi.md#testInlineAdditionalProperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
[**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data [**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data
[**testQueryParameterCollectionFormat**](FakeApi.md#testQueryParameterCollectionFormat) | **PUT** /fake/test-query-paramters |
<a name="fakeHealthGet"></a> <a name="fakeHealthGet"></a>
@@ -670,3 +671,57 @@ No authorization required
- **Content-Type**: application/x-www-form-urlencoded - **Content-Type**: application/x-www-form-urlencoded
- **Accept**: Not defined - **Accept**: Not defined
<a name="testQueryParameterCollectionFormat"></a>
# **testQueryParameterCollectionFormat**
> testQueryParameterCollectionFormat(pipe, ioutil, http, url, context)
To test the collection format in query parameters
### Example
```kotlin
// Import classes:
//import org.openapitools.client.infrastructure.*
//import org.openapitools.client.models.*
val apiInstance = FakeApi()
val pipe : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
val ioutil : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
val http : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
val url : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
val context : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
try {
apiInstance.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context)
} catch (e: ClientException) {
println("4xx response calling FakeApi#testQueryParameterCollectionFormat")
e.printStackTrace()
} catch (e: ServerException) {
println("5xx response calling FakeApi#testQueryParameterCollectionFormat")
e.printStackTrace()
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pipe** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
**ioutil** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
**http** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
**url** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
**context** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
### Return type
null (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined

View File

@@ -51,8 +51,8 @@ class AnotherFakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Client ResponseType.Success -> (response as Success<*>).data as Client
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -50,8 +50,8 @@ class DefaultApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") :
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as InlineResponseDefault ResponseType.Success -> (response as Success<*>).data as InlineResponseDefault
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -54,8 +54,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as HealthCheckResult ResponseType.Success -> (response as Success<*>).data as HealthCheckResult
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -85,8 +85,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Boolean ResponseType.Success -> (response as Success<*>).data as kotlin.Boolean
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -116,8 +116,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as OuterComposite ResponseType.Success -> (response as Success<*>).data as OuterComposite
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -147,8 +147,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as java.math.BigDecimal ResponseType.Success -> (response as Success<*>).data as java.math.BigDecimal
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -178,8 +178,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -208,8 +208,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -239,8 +239,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -270,8 +270,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Client ResponseType.Success -> (response as Success<*>).data as Client
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -313,8 +313,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -350,8 +350,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -385,8 +385,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -415,8 +415,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -446,8 +446,42 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
}
/**
*
* To test the collection format in query parameters
* @param pipe
* @param ioutil
* @param http
* @param url
* @param context
* @return void
*/
fun testQueryParameterCollectionFormat(pipe: kotlin.Array<kotlin.String>, ioutil: kotlin.Array<kotlin.String>, http: kotlin.Array<kotlin.String>, url: kotlin.Array<kotlin.String>, context: kotlin.Array<kotlin.String>) : Unit {
val localVariableBody: kotlin.Any? = null
val localVariableQuery: MultiValueMap = mapOf("pipe" to toMultiValue(pipe.toList(), "multi"), "ioutil" to toMultiValue(ioutil.toList(), "csv"), "http" to toMultiValue(http.toList(), "space"), "url" to toMultiValue(url.toList(), "csv"), "context" to toMultiValue(context.toList(), "multi"))
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
val localVariableConfig = RequestConfig(
RequestMethod.PUT,
"/fake/test-query-paramters",
query = localVariableQuery,
headers = localVariableHeaders
)
val response = request<Any?>(
localVariableConfig,
localVariableBody
)
return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -51,8 +51,8 @@ class FakeClassnameTags123Api(basePath: kotlin.String = "http://petstore.swagger
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Client ResponseType.Success -> (response as Success<*>).data as Client
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -51,8 +51,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -82,8 +82,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -113,8 +113,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -144,8 +144,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -175,8 +175,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Pet ResponseType.Success -> (response as Success<*>).data as Pet
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -205,8 +205,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -237,8 +237,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -270,8 +270,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -303,8 +303,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -50,8 +50,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -80,8 +80,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int> ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -111,8 +111,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -142,8 +142,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -50,8 +50,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -80,8 +80,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -110,8 +110,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -140,8 +140,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -171,8 +171,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as User ResponseType.Success -> (response as Success<*>).data as User
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -203,8 +203,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -232,8 +232,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@@ -263,8 +263,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@@ -2,10 +2,12 @@ package org.openapitools.client.infrastructure
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.RequestBody import okhttp3.RequestBody
import okhttp3.MediaType import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.ResponseBody import okhttp3.ResponseBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request import okhttp3.Request
import java.io.File import java.io.File
@@ -36,8 +38,8 @@ open class ApiClient(val baseUrl: String) {
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody = protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
when { when {
content is File -> RequestBody.create( content is File -> content.asRequestBody(
MediaType.parse(mediaType), content mediaType.toMediaTypeOrNull()
) )
mediaType == FormDataMediaType || mediaType == FormUrlEncMediaType -> { mediaType == FormDataMediaType || mediaType == FormUrlEncMediaType -> {
FormBody.Builder().apply { FormBody.Builder().apply {
@@ -48,12 +50,12 @@ open class ApiClient(val baseUrl: String) {
} }
}.build() }.build()
} }
mediaType == JsonMediaType -> RequestBody.create( mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
MediaType.parse(mediaType), Serializer.moshi.adapter(T::class.java).toJson(content) mediaType.toMediaTypeOrNull()
) )
mediaType == XmlMediaType -> TODO("xml not currently supported.") mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers // TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.") else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
} }
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
@@ -66,23 +68,27 @@ open class ApiClient(val baseUrl: String) {
} }
return when(mediaType) { return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.") else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
} }
} }
protected fun updateAuthParams(requestConfig: RequestConfig) { protected fun updateAuthParams(requestConfig: RequestConfig) {
if (requestConfig.headers["api_key"].isNullOrEmpty()) { if (requestConfig.headers["api_key"].isNullOrEmpty()) {
if (apiKeyPrefix["api_key"] != null) { if (apiKey["api_key"] != null) {
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"] + " " + apiKey["api_key"] if (apiKeyPrefix["api_key"] != null) {
} else { requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
requestConfig.headers["api_key"] = apiKey["api_key"] } else {
requestConfig.headers["api_key"] = apiKey["api_key"]!!
}
} }
} }
if (requestConfig.query["api_key_query"].isNullOrEmpty()) { if (requestConfig.query["api_key_query"].isNullOrEmpty()) {
if (apiKeyPrefix["api_key_query"] != null) { if (apiKey["api_key_query"] != null) {
requestConfig.query["api_key_query"] = apiKeyPrefix["api_key_query"] + " " + apiKey["api_key_query"] if (apiKeyPrefix["api_key_query"] != null) {
} else { requestConfig.query["api_key_query"] = apiKeyPrefix["api_key_query"]!! + " " + apiKey["api_key_query"]!!
requestConfig.query["api_key_query"] = apiKey["api_key_query"] } else {
requestConfig.query["api_key_query"] = apiKey["api_key_query"]!!
}
} }
} }
if (requestConfig.headers[Authorization].isNullOrEmpty()) { if (requestConfig.headers[Authorization].isNullOrEmpty()) {
@@ -97,7 +103,7 @@ open class ApiClient(val baseUrl: String) {
} }
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> { protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.") val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
// take authMethod from operation // take authMethod from operation
updateAuthParams(requestConfig) updateAuthParams(requestConfig)
@@ -150,29 +156,29 @@ open class ApiClient(val baseUrl: String) {
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
when { when {
response.isRedirect -> return Redirection( response.isRedirect -> return Redirection(
response.code(), response.code,
response.headers().toMultimap() response.headers.toMultimap()
) )
response.isInformational -> return Informational( response.isInformational -> return Informational(
response.message(), response.message,
response.code(), response.code,
response.headers().toMultimap() response.headers.toMultimap()
) )
response.isSuccessful -> return Success( response.isSuccessful -> return Success(
responseBody(response.body(), accept), responseBody(response.body, accept),
response.code(), response.code,
response.headers().toMultimap() response.headers.toMultimap()
) )
response.isClientError -> return ClientError( response.isClientError -> return ClientError(
response.body()?.string(), response.body?.string(),
response.code(), response.code,
response.headers().toMultimap() response.headers.toMultimap()
) )
else -> return ServerError( else -> return ServerError(
null, null,
response.body()?.string(), response.body?.string(),
response.code(), response.code,
response.headers().toMultimap() response.headers.toMultimap()
) )
} }
} }

View File

@@ -5,19 +5,19 @@ import okhttp3.Response
/** /**
* Provides an extension to evaluation whether the response is a 1xx code * Provides an extension to evaluation whether the response is a 1xx code
*/ */
val Response.isInformational : Boolean get() = this.code() in 100..199 val Response.isInformational : Boolean get() = this.code in 100..199
/** /**
* Provides an extension to evaluation whether the response is a 3xx code * Provides an extension to evaluation whether the response is a 3xx code
*/ */
val Response.isRedirect : Boolean get() = this.code() in 300..399 val Response.isRedirect : Boolean get() = this.code in 300..399
/** /**
* Provides an extension to evaluation whether the response is a 4xx code * Provides an extension to evaluation whether the response is a 4xx code
*/ */
val Response.isClientError : Boolean get() = this.code() in 400..499 val Response.isClientError : Boolean get() = this.code in 400..499
/** /**
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
*/ */
val Response.isServerError : Boolean get() = this.code() in 500..999 val Response.isServerError : Boolean get() = this.code in 500..999

View File

@@ -22,7 +22,7 @@ data class EnumArrays (
@Json(name = "just_symbol") @Json(name = "just_symbol")
val justSymbol: EnumArrays.JustSymbol? = null, val justSymbol: EnumArrays.JustSymbol? = null,
@Json(name = "array_enum") @Json(name = "array_enum")
val arrayEnum: EnumArrays.ArrayEnum? = null val arrayEnum: kotlin.Array<EnumArrays.ArrayEnum>? = null
) { ) {
/** /**
@@ -43,7 +43,7 @@ data class EnumArrays (
* *
* Values: fish,crab * Values: fish,crab
*/ */
enum class ArrayEnum(val value: kotlin.Array&lt;kotlin.String&gt;){ enum class ArrayEnum(val value: kotlin.String){
@Json(name = "fish") @Json(name = "fish")
fish("fish"), fish("fish"),

View File

@@ -20,14 +20,18 @@ import com.squareup.moshi.Json
*/ */
enum class EnumClass(val value: kotlin.String){ enum class EnumClass(val value: kotlin.String){
@Json(name = "_abc") @Json(name = "_abc")
abc("_abc"), abc("_abc"),
@Json(name = "-efg") @Json(name = "-efg")
minusEfg("-efg"), minusEfg("-efg"),
@Json(name = "(xyz)") @Json(name = "(xyz)")
leftParenthesisXyzRightParenthesis("(xyz)"); leftParenthesisXyzRightParenthesis("(xyz)");
} }

View File

@@ -21,7 +21,7 @@ import com.squareup.moshi.Json
data class InlineObject2 ( data class InlineObject2 (
/* Form parameter enum test (string array) */ /* Form parameter enum test (string array) */
@Json(name = "enum_form_string_array") @Json(name = "enum_form_string_array")
val enumFormStringArray: InlineObject2.EnumFormStringArray? = null, val enumFormStringArray: kotlin.Array<InlineObject2.EnumFormStringArray>? = null,
/* Form parameter enum test (string) */ /* Form parameter enum test (string) */
@Json(name = "enum_form_string") @Json(name = "enum_form_string")
val enumFormString: InlineObject2.EnumFormString? = null val enumFormString: InlineObject2.EnumFormString? = null
@@ -31,7 +31,7 @@ data class InlineObject2 (
* Form parameter enum test (string array) * Form parameter enum test (string array)
* Values: greaterThan,dollar * Values: greaterThan,dollar
*/ */
enum class EnumFormStringArray(val value: kotlin.Array&lt;kotlin.String&gt;){ enum class EnumFormStringArray(val value: kotlin.String){
@Json(name = ">") @Json(name = ">")
greaterThan(">"), greaterThan(">"),

View File

@@ -35,7 +35,7 @@ data class MapTest (
* *
* Values: uPPER,lower * Values: uPPER,lower
*/ */
enum class MapOfEnumString(val value: kotlin.collections.Map&lt;kotlin.String, kotlin.String&gt;){ enum class MapOfEnumString(val value: kotlin.collections.Map<kotlin.String, kotlin.String>){
@Json(name = "UPPER") @Json(name = "UPPER")
uPPER("UPPER"), uPPER("UPPER"),

View File

@@ -20,14 +20,18 @@ import com.squareup.moshi.Json
*/ */
enum class OuterEnum(val value: kotlin.String){ enum class OuterEnum(val value: kotlin.String){
@Json(name = "placed") @Json(name = "placed")
placed("placed"), placed("placed"),
@Json(name = "approved") @Json(name = "approved")
approved("approved"), approved("approved"),
@Json(name = "delivered") @Json(name = "delivered")
delivered("delivered"); delivered("delivered");
} }

View File

@@ -20,14 +20,18 @@ import com.squareup.moshi.Json
*/ */
enum class OuterEnumDefaultValue(val value: kotlin.String){ enum class OuterEnumDefaultValue(val value: kotlin.String){
@Json(name = "placed") @Json(name = "placed")
placed("placed"), placed("placed"),
@Json(name = "approved") @Json(name = "approved")
approved("approved"), approved("approved"),
@Json(name = "delivered") @Json(name = "delivered")
delivered("delivered"); delivered("delivered");
} }

View File

@@ -20,14 +20,18 @@ import com.squareup.moshi.Json
*/ */
enum class OuterEnumInteger(val value: kotlin.Int){ enum class OuterEnumInteger(val value: kotlin.Int){
@Json(name = "0") @Json(name = "0")
_0(0), _0(0),
@Json(name = "1") @Json(name = "1")
_1(1), _1(1),
@Json(name = "2") @Json(name = "2")
_2(2); _2(2);
} }

View File

@@ -20,14 +20,18 @@ import com.squareup.moshi.Json
*/ */
enum class OuterEnumIntegerDefaultValue(val value: kotlin.Int){ enum class OuterEnumIntegerDefaultValue(val value: kotlin.Int){
@Json(name = "0") @Json(name = "0")
_0(0), _0(0),
@Json(name = "1") @Json(name = "1")
_1(1), _1(1),
@Json(name = "2") @Json(name = "2")
_2(2); _2(2);
} }