Skip to content

Commit 38c6220

Browse files
wing328detomarco
andauthored
fix(kotlin-client): jvm-spring-webclient: fix compile error when kotlin detects nullable body (#22509)
* fix(kotlin-client): jvm-spring-webclient: fix compile error when kotlin detects nullable body * update samples --------- Co-authored-by: detomarco <[email protected]>
1 parent 74c551c commit 38c6220

File tree

13 files changed

+43
-43
lines changed

13 files changed

+43
-43
lines changed

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-spring-webclient/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {{packageName}}.infrastructure.*
7272
{{/isDeprecated}}
7373
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{#isEnum}}{{#isContainer}}kotlin.collections.List<{{enumName}}{{operationIdCamelCase}}>{{/isContainer}}{{^isContainer}}{{enumName}}{{operationIdCamelCase}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}?{{#defaultValue}} = {{>param_default_value}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): Mono<{{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}> {
7474
return {{operationId}}WithHttpInfo({{#allParams}}{{{paramName}}} = {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
75-
.map { {{#returnType}}it.body{{/returnType}}{{^returnType}}Unit{{/returnType}} }
75+
.map { {{#returnType}}it.body!!{{/returnType}}{{^returnType}}Unit{{/returnType}} }
7676
}
7777

7878
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/AuthApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open class AuthApi(client: WebClient) : ApiClient(client) {
4343
@Throws(WebClientResponseException::class)
4444
fun testAuthHttpBasic(): Mono<kotlin.String> {
4545
return testAuthHttpBasicWithHttpInfo()
46-
.map { it.body }
46+
.map { it.body!! }
4747
}
4848

4949
@Throws(WebClientResponseException::class)
@@ -78,7 +78,7 @@ open class AuthApi(client: WebClient) : ApiClient(client) {
7878
@Throws(WebClientResponseException::class)
7979
fun testAuthHttpBearer(): Mono<kotlin.String> {
8080
return testAuthHttpBearerWithHttpInfo()
81-
.map { it.body }
81+
.map { it.body!! }
8282
}
8383

8484
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/BodyApi.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
4545
@Throws(WebClientResponseException::class)
4646
fun testBinaryGif(): Mono<java.io.File> {
4747
return testBinaryGifWithHttpInfo()
48-
.map { it.body }
48+
.map { it.body!! }
4949
}
5050

5151
@Throws(WebClientResponseException::class)
@@ -80,7 +80,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
8080
@Throws(WebClientResponseException::class)
8181
fun testBodyApplicationOctetstreamBinary(body: java.io.File? = null): Mono<kotlin.String> {
8282
return testBodyApplicationOctetstreamBinaryWithHttpInfo(body = body)
83-
.map { it.body }
83+
.map { it.body!! }
8484
}
8585

8686
@Throws(WebClientResponseException::class)
@@ -116,7 +116,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
116116
@Throws(WebClientResponseException::class)
117117
fun testBodyMultipartFormdataArrayOfBinary(files: kotlin.collections.List<java.io.File>): Mono<kotlin.String> {
118118
return testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files = files)
119-
.map { it.body }
119+
.map { it.body!! }
120120
}
121121

122122
@Throws(WebClientResponseException::class)
@@ -152,7 +152,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
152152
@Throws(WebClientResponseException::class)
153153
fun testBodyMultipartFormdataSingleBinary(myFile: java.io.File? = null): Mono<kotlin.String> {
154154
return testBodyMultipartFormdataSingleBinaryWithHttpInfo(myFile = myFile)
155-
.map { it.body }
155+
.map { it.body!! }
156156
}
157157

158158
@Throws(WebClientResponseException::class)
@@ -188,7 +188,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
188188
@Throws(WebClientResponseException::class)
189189
fun testEchoBodyFreeFormObjectResponseString(body: kotlin.Any? = null): Mono<kotlin.String> {
190190
return testEchoBodyFreeFormObjectResponseStringWithHttpInfo(body = body)
191-
.map { it.body }
191+
.map { it.body!! }
192192
}
193193

194194
@Throws(WebClientResponseException::class)
@@ -224,7 +224,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
224224
@Throws(WebClientResponseException::class)
225225
fun testEchoBodyPet(pet: Pet? = null): Mono<Pet> {
226226
return testEchoBodyPetWithHttpInfo(pet = pet)
227-
.map { it.body }
227+
.map { it.body!! }
228228
}
229229

230230
@Throws(WebClientResponseException::class)
@@ -260,7 +260,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
260260
@Throws(WebClientResponseException::class)
261261
fun testEchoBodyPetResponseString(pet: Pet? = null): Mono<kotlin.String> {
262262
return testEchoBodyPetResponseStringWithHttpInfo(pet = pet)
263-
.map { it.body }
263+
.map { it.body!! }
264264
}
265265

266266
@Throws(WebClientResponseException::class)
@@ -296,7 +296,7 @@ open class BodyApi(client: WebClient) : ApiClient(client) {
296296
@Throws(WebClientResponseException::class)
297297
fun testEchoBodyTagResponseString(tag: Tag? = null): Mono<kotlin.String> {
298298
return testEchoBodyTagResponseStringWithHttpInfo(tag = tag)
299-
.map { it.body }
299+
.map { it.body!! }
300300
}
301301

302302
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/FormApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open class FormApi(client: WebClient) : ApiClient(client) {
4343
@Throws(WebClientResponseException::class)
4444
fun testFormIntegerBooleanString(integerForm: kotlin.Int? = null, booleanForm: kotlin.Boolean? = null, stringForm: kotlin.String? = null): Mono<kotlin.String> {
4545
return testFormIntegerBooleanStringWithHttpInfo(integerForm = integerForm, booleanForm = booleanForm, stringForm = stringForm)
46-
.map { it.body }
46+
.map { it.body!! }
4747
}
4848

4949
@Throws(WebClientResponseException::class)
@@ -81,7 +81,7 @@ open class FormApi(client: WebClient) : ApiClient(client) {
8181
@Throws(WebClientResponseException::class)
8282
fun testFormOneof(form1: kotlin.String? = null, form2: kotlin.Int? = null, form3: kotlin.String? = null, form4: kotlin.Boolean? = null, id: kotlin.Long? = null, name: kotlin.String? = null): Mono<kotlin.String> {
8383
return testFormOneofWithHttpInfo(form1 = form1, form2 = form2, form3 = form3, form4 = form4, id = id, name = name)
84-
.map { it.body }
84+
.map { it.body!! }
8585
}
8686

8787
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ open class HeaderApi(client: WebClient) : ApiClient(client) {
5353
@Throws(WebClientResponseException::class)
5454
fun testHeaderIntegerBooleanStringEnums(integerHeader: kotlin.Int? = null, booleanHeader: kotlin.Boolean? = null, stringHeader: kotlin.String? = null, enumNonrefStringHeader: EnumNonrefStringHeaderTestHeaderIntegerBooleanStringEnums? = null, enumRefStringHeader: StringEnumRef? = null): Mono<kotlin.String> {
5555
return testHeaderIntegerBooleanStringEnumsWithHttpInfo(integerHeader = integerHeader, booleanHeader = booleanHeader, stringHeader = stringHeader, enumNonrefStringHeader = enumNonrefStringHeader, enumRefStringHeader = enumRefStringHeader)
56-
.map { it.body }
56+
.map { it.body!! }
5757
}
5858

5959
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/PathApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ open class PathApi(client: WebClient) : ApiClient(client) {
5353
@Throws(WebClientResponseException::class)
5454
fun testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString: kotlin.String, pathInteger: kotlin.Int, enumNonrefStringPath: EnumNonrefStringPathTestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath, enumRefStringPath: StringEnumRef): Mono<kotlin.String> {
5555
return testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo(pathString = pathString, pathInteger = pathInteger, enumNonrefStringPath = enumNonrefStringPath, enumRefStringPath = enumRefStringPath)
56-
.map { it.body }
56+
.map { it.body!! }
5757
}
5858

5959
@Throws(WebClientResponseException::class)

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/apis/QueryApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
5555
@Throws(WebClientResponseException::class)
5656
fun testEnumRefString(enumNonrefStringQuery: EnumNonrefStringQueryTestEnumRefString? = null, enumRefStringQuery: StringEnumRef? = null): Mono<kotlin.String> {
5757
return testEnumRefStringWithHttpInfo(enumNonrefStringQuery = enumNonrefStringQuery, enumRefStringQuery = enumRefStringQuery)
58-
.map { it.body }
58+
.map { it.body!! }
5959
}
6060

6161
@Throws(WebClientResponseException::class)
@@ -98,7 +98,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
9898
@Throws(WebClientResponseException::class)
9999
fun testQueryDatetimeDateString(datetimeQuery: java.time.OffsetDateTime? = null, dateQuery: java.time.LocalDate? = null, stringQuery: kotlin.String? = null): Mono<kotlin.String> {
100100
return testQueryDatetimeDateStringWithHttpInfo(datetimeQuery = datetimeQuery, dateQuery = dateQuery, stringQuery = stringQuery)
101-
.map { it.body }
101+
.map { it.body!! }
102102
}
103103

104104
@Throws(WebClientResponseException::class)
@@ -144,7 +144,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
144144
@Throws(WebClientResponseException::class)
145145
fun testQueryIntegerBooleanString(integerQuery: kotlin.Int? = null, booleanQuery: kotlin.Boolean? = null, stringQuery: kotlin.String? = null): Mono<kotlin.String> {
146146
return testQueryIntegerBooleanStringWithHttpInfo(integerQuery = integerQuery, booleanQuery = booleanQuery, stringQuery = stringQuery)
147-
.map { it.body }
147+
.map { it.body!! }
148148
}
149149

150150
@Throws(WebClientResponseException::class)
@@ -190,7 +190,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
190190
@Throws(WebClientResponseException::class)
191191
fun testQueryStyleDeepObjectExplodeTrueObject(queryObject: Pet? = null): Mono<kotlin.String> {
192192
return testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo(queryObject = queryObject)
193-
.map { it.body }
193+
.map { it.body!! }
194194
}
195195

196196
@Throws(WebClientResponseException::class)
@@ -230,7 +230,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
230230
@Throws(WebClientResponseException::class)
231231
fun testQueryStyleFormExplodeTrueArrayString(queryObject: TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter? = null): Mono<kotlin.String> {
232232
return testQueryStyleFormExplodeTrueArrayStringWithHttpInfo(queryObject = queryObject)
233-
.map { it.body }
233+
.map { it.body!! }
234234
}
235235

236236
@Throws(WebClientResponseException::class)
@@ -270,7 +270,7 @@ open class QueryApi(client: WebClient) : ApiClient(client) {
270270
@Throws(WebClientResponseException::class)
271271
fun testQueryStyleFormExplodeTrueObject(queryObject: Pet? = null): Mono<kotlin.String> {
272272
return testQueryStyleFormExplodeTrueObjectWithHttpInfo(queryObject = queryObject)
273-
.map { it.body }
273+
.map { it.body!! }
274274
}
275275

276276
@Throws(WebClientResponseException::class)

samples/client/petstore/kotlin-jvm-spring-2-webclient/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
4545
@Throws(WebClientResponseException::class)
4646
fun addPet(pet: Pet): Mono<Pet> {
4747
return addPetWithHttpInfo(pet = pet)
48-
.map { it.body }
48+
.map { it.body!! }
4949
}
5050

5151
@Throws(WebClientResponseException::class)
@@ -127,7 +127,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
127127
@Throws(WebClientResponseException::class)
128128
fun findPetsByStatus(status: kotlin.collections.List<StatusFindPetsByStatus>): Mono<kotlin.collections.List<Pet>> {
129129
return findPetsByStatusWithHttpInfo(status = status)
130-
.map { it.body }
130+
.map { it.body!! }
131131
}
132132

133133
@Throws(WebClientResponseException::class)
@@ -166,7 +166,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
166166
@Deprecated(message = "This operation is deprecated.")
167167
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): Mono<kotlin.collections.List<Pet>> {
168168
return findPetsByTagsWithHttpInfo(tags = tags)
169-
.map { it.body }
169+
.map { it.body!! }
170170
}
171171

172172
@Throws(WebClientResponseException::class)
@@ -206,7 +206,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
206206
@Throws(WebClientResponseException::class)
207207
fun getPetById(petId: kotlin.Long): Mono<Pet> {
208208
return getPetByIdWithHttpInfo(petId = petId)
209-
.map { it.body }
209+
.map { it.body!! }
210210
}
211211

212212
@Throws(WebClientResponseException::class)
@@ -242,7 +242,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
242242
@Throws(WebClientResponseException::class)
243243
fun updatePet(pet: Pet): Mono<Pet> {
244244
return updatePetWithHttpInfo(pet = pet)
245-
.map { it.body }
245+
.map { it.body!! }
246246
}
247247

248248
@Throws(WebClientResponseException::class)
@@ -316,7 +316,7 @@ open class PetApi(client: WebClient) : ApiClient(client) {
316316
@Throws(WebClientResponseException::class)
317317
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: java.io.File? = null): Mono<ModelApiResponse> {
318318
return uploadFileWithHttpInfo(petId = petId, additionalMetadata = additionalMetadata, file = file)
319-
.map { it.body }
319+
.map { it.body!! }
320320
}
321321

322322
@Throws(WebClientResponseException::class)

samples/client/petstore/kotlin-jvm-spring-2-webclient/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ open class StoreApi(client: WebClient) : ApiClient(client) {
7979
@Throws(WebClientResponseException::class)
8080
fun getInventory(): Mono<kotlin.collections.Map<kotlin.String, kotlin.Int>> {
8181
return getInventoryWithHttpInfo()
82-
.map { it.body }
82+
.map { it.body!! }
8383
}
8484

8585
@Throws(WebClientResponseException::class)
@@ -114,7 +114,7 @@ open class StoreApi(client: WebClient) : ApiClient(client) {
114114
@Throws(WebClientResponseException::class)
115115
fun getOrderById(orderId: kotlin.Long): Mono<Order> {
116116
return getOrderByIdWithHttpInfo(orderId = orderId)
117-
.map { it.body }
117+
.map { it.body!! }
118118
}
119119

120120
@Throws(WebClientResponseException::class)
@@ -150,7 +150,7 @@ open class StoreApi(client: WebClient) : ApiClient(client) {
150150
@Throws(WebClientResponseException::class)
151151
fun placeOrder(order: Order): Mono<Order> {
152152
return placeOrderWithHttpInfo(order = order)
153-
.map { it.body }
153+
.map { it.body!! }
154154
}
155155

156156
@Throws(WebClientResponseException::class)

samples/client/petstore/kotlin-jvm-spring-2-webclient/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ open class UserApi(client: WebClient) : ApiClient(client) {
184184
@Throws(WebClientResponseException::class)
185185
fun getUserByName(username: kotlin.String): Mono<User> {
186186
return getUserByNameWithHttpInfo(username = username)
187-
.map { it.body }
187+
.map { it.body!! }
188188
}
189189

190190
@Throws(WebClientResponseException::class)
@@ -220,7 +220,7 @@ open class UserApi(client: WebClient) : ApiClient(client) {
220220
@Throws(WebClientResponseException::class)
221221
fun loginUser(username: kotlin.String, password: kotlin.String): Mono<kotlin.String> {
222222
return loginUserWithHttpInfo(username = username, password = password)
223-
.map { it.body }
223+
.map { it.body!! }
224224
}
225225

226226
@Throws(WebClientResponseException::class)

0 commit comments

Comments
 (0)