Skip to content

Commit 1f5aa22

Browse files
armandmgtwing328
authored andcommitted
Fix null assignation to header/query param map (#3749)
Also regenerates the clients
1 parent dfb4c13 commit 1f5aa22

File tree

21 files changed

+253
-134
lines changed

21 files changed

+253
-134
lines changed

modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,22 @@ open class ApiClient(val baseUrl: String) {
8282
{{#isKeyInQuery}}
8383
if (requestConfig.query["{{keyParamName}}"].isNullOrEmpty()) {
8484
{{/isKeyInQuery}}
85-
if (apiKeyPrefix["{{keyParamName}}"] != null) {
86-
{{#isKeyInHeader}}
87-
requestConfig.headers["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"] + " " + apiKey["{{keyParamName}}"]
88-
{{/isKeyInHeader}}
89-
{{#isKeyInQuery}}
90-
requestConfig.query["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"] + " " + apiKey["{{keyParamName}}"]
91-
{{/isKeyInQuery}}
92-
} else {
93-
{{#isKeyInHeader}}
94-
requestConfig.headers["{{keyParamName}}"] = apiKey["{{keyParamName}}"]
95-
{{/isKeyInHeader}}
96-
{{#isKeyInQuery}}
97-
requestConfig.query["{{keyParamName}}"] = apiKey["{{keyParamName}}"]
98-
{{/isKeyInQuery}}
85+
if (apiKey["{{keyParamName}}"] != null) {
86+
if (apiKeyPrefix["{{keyParamName}}"] != null) {
87+
{{#isKeyInHeader}}
88+
requestConfig.headers["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"]!! + " " + apiKey["{{keyParamName}}"]!!
89+
{{/isKeyInHeader}}
90+
{{#isKeyInQuery}}
91+
requestConfig.query["{{keyParamName}}"] = apiKeyPrefix["{{keyParamName}}"]!! + " " + apiKey["{{keyParamName}}"]!!
92+
{{/isKeyInQuery}}
93+
} else {
94+
{{#isKeyInHeader}}
95+
requestConfig.headers["{{keyParamName}}"] = apiKey["{{keyParamName}}"]!!
96+
{{/isKeyInHeader}}
97+
{{#isKeyInQuery}}
98+
requestConfig.query["{{keyParamName}}"] = apiKey["{{keyParamName}}"]!!
99+
{{/isKeyInQuery}}
100+
}
99101
}
100102
}
101103
{{/isApiKey}}

samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ open class ApiClient(val baseUrl: String) {
7474

7575
protected fun updateAuthParams(requestConfig: RequestConfig) {
7676
if (requestConfig.headers["api_key"].isNullOrEmpty()) {
77-
if (apiKeyPrefix["api_key"] != null) {
78-
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"] + " " + apiKey["api_key"]
79-
} else {
80-
requestConfig.headers["api_key"] = apiKey["api_key"]
77+
if (apiKey["api_key"] != null) {
78+
if (apiKeyPrefix["api_key"] != null) {
79+
requestConfig.headers["api_key"] = apiKeyPrefix["api_key"]!! + " " + apiKey["api_key"]!!
80+
} else {
81+
requestConfig.headers["api_key"] = apiKey["api_key"]!!
82+
}
8183
}
8284
}
8385
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.0-SNAPSHOT
1+
4.1.1-SNAPSHOT

samples/openapi3/client/petstore/kotlin/docs/FakeApi.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Method | HTTP request | Description
1717
[**testGroupParameters**](FakeApi.md#testGroupParameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
1818
[**testInlineAdditionalProperties**](FakeApi.md#testInlineAdditionalProperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
1919
[**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data
20+
[**testQueryParameterCollectionFormat**](FakeApi.md#testQueryParameterCollectionFormat) | **PUT** /fake/test-query-paramters |
2021

2122

2223
<a name="fakeHealthGet"></a>
@@ -670,3 +671,57 @@ No authorization required
670671
- **Content-Type**: application/x-www-form-urlencoded
671672
- **Accept**: Not defined
672673

674+
<a name="testQueryParameterCollectionFormat"></a>
675+
# **testQueryParameterCollectionFormat**
676+
> testQueryParameterCollectionFormat(pipe, ioutil, http, url, context)
677+
678+
679+
680+
To test the collection format in query parameters
681+
682+
### Example
683+
```kotlin
684+
// Import classes:
685+
//import org.openapitools.client.infrastructure.*
686+
//import org.openapitools.client.models.*
687+
688+
val apiInstance = FakeApi()
689+
val pipe : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
690+
val ioutil : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
691+
val http : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
692+
val url : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
693+
val context : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> |
694+
try {
695+
apiInstance.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context)
696+
} catch (e: ClientException) {
697+
println("4xx response calling FakeApi#testQueryParameterCollectionFormat")
698+
e.printStackTrace()
699+
} catch (e: ServerException) {
700+
println("5xx response calling FakeApi#testQueryParameterCollectionFormat")
701+
e.printStackTrace()
702+
}
703+
```
704+
705+
### Parameters
706+
707+
Name | Type | Description | Notes
708+
------------- | ------------- | ------------- | -------------
709+
**pipe** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
710+
**ioutil** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
711+
**http** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
712+
**url** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
713+
**context** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| |
714+
715+
### Return type
716+
717+
null (empty response body)
718+
719+
### Authorization
720+
721+
No authorization required
722+
723+
### HTTP request headers
724+
725+
- **Content-Type**: Not defined
726+
- **Accept**: Not defined
727+

samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class AnotherFakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2
5151

5252
return when (response.responseType) {
5353
ResponseType.Success -> (response as Success<*>).data as Client
54-
ResponseType.Informational -> TODO()
55-
ResponseType.Redirection -> TODO()
54+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
55+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
5656
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
5757
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
5858
}

samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class DefaultApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") :
5050

5151
return when (response.responseType) {
5252
ResponseType.Success -> (response as Success<*>).data as InlineResponseDefault
53-
ResponseType.Informational -> TODO()
54-
ResponseType.Redirection -> TODO()
53+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
54+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
5555
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
5656
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
5757
}

samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
5454

5555
return when (response.responseType) {
5656
ResponseType.Success -> (response as Success<*>).data as HealthCheckResult
57-
ResponseType.Informational -> TODO()
58-
ResponseType.Redirection -> TODO()
57+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
58+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
5959
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
6060
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
6161
}
@@ -85,8 +85,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
8585

8686
return when (response.responseType) {
8787
ResponseType.Success -> (response as Success<*>).data as kotlin.Boolean
88-
ResponseType.Informational -> TODO()
89-
ResponseType.Redirection -> TODO()
88+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
89+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
9090
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
9191
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
9292
}
@@ -116,8 +116,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
116116

117117
return when (response.responseType) {
118118
ResponseType.Success -> (response as Success<*>).data as OuterComposite
119-
ResponseType.Informational -> TODO()
120-
ResponseType.Redirection -> TODO()
119+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
120+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
121121
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
122122
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
123123
}
@@ -147,8 +147,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
147147

148148
return when (response.responseType) {
149149
ResponseType.Success -> (response as Success<*>).data as java.math.BigDecimal
150-
ResponseType.Informational -> TODO()
151-
ResponseType.Redirection -> TODO()
150+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
151+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
152152
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
153153
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
154154
}
@@ -178,8 +178,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
178178

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

209209
return when (response.responseType) {
210210
ResponseType.Success -> Unit
211-
ResponseType.Informational -> TODO()
212-
ResponseType.Redirection -> TODO()
211+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
212+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
213213
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
214214
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
215215
}
@@ -239,8 +239,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
239239

240240
return when (response.responseType) {
241241
ResponseType.Success -> Unit
242-
ResponseType.Informational -> TODO()
243-
ResponseType.Redirection -> TODO()
242+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
243+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
244244
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
245245
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
246246
}
@@ -270,8 +270,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
270270

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

314314
return when (response.responseType) {
315315
ResponseType.Success -> Unit
316-
ResponseType.Informational -> TODO()
317-
ResponseType.Redirection -> TODO()
316+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
317+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
318318
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
319319
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
320320
}
@@ -350,8 +350,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
350350

351351
return when (response.responseType) {
352352
ResponseType.Success -> Unit
353-
ResponseType.Informational -> TODO()
354-
ResponseType.Redirection -> TODO()
353+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
354+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
355355
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
356356
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
357357
}
@@ -385,8 +385,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
385385

386386
return when (response.responseType) {
387387
ResponseType.Success -> Unit
388-
ResponseType.Informational -> TODO()
389-
ResponseType.Redirection -> TODO()
388+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
389+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
390390
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
391391
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
392392
}
@@ -415,8 +415,8 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
415415

416416
return when (response.responseType) {
417417
ResponseType.Success -> Unit
418-
ResponseType.Informational -> TODO()
419-
ResponseType.Redirection -> TODO()
418+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
419+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
420420
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
421421
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
422422
}
@@ -446,8 +446,42 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap
446446

447447
return when (response.responseType) {
448448
ResponseType.Success -> Unit
449-
ResponseType.Informational -> TODO()
450-
ResponseType.Redirection -> TODO()
449+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
450+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
451+
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
452+
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
453+
}
454+
}
455+
456+
/**
457+
*
458+
* To test the collection format in query parameters
459+
* @param pipe
460+
* @param ioutil
461+
* @param http
462+
* @param url
463+
* @param context
464+
* @return void
465+
*/
466+
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 {
467+
val localVariableBody: kotlin.Any? = null
468+
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"))
469+
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
470+
val localVariableConfig = RequestConfig(
471+
RequestMethod.PUT,
472+
"/fake/test-query-paramters",
473+
query = localVariableQuery,
474+
headers = localVariableHeaders
475+
)
476+
val response = request<Any?>(
477+
localVariableConfig,
478+
localVariableBody
479+
)
480+
481+
return when (response.responseType) {
482+
ResponseType.Success -> Unit
483+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
484+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
451485
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
452486
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
453487
}

0 commit comments

Comments
 (0)