Skip to content

Commit 8813ead

Browse files
committed
update kotlin samples
1 parent 4c72ac0 commit 8813ead

File tree

9 files changed

+57
-35
lines changed

9 files changed

+57
-35
lines changed

samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/PetApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
4040
query = localVariableQuery,
4141
headers = localVariableHeaders
4242
)
43-
val response = request<Any?>(
43+
val response = request<Unit>(
4444
localVariableConfig,
4545
localVariableBody
4646
)
@@ -78,7 +78,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
7878
query = localVariableQuery,
7979
headers = localVariableHeaders
8080
)
81-
val response = request<Any?>(
81+
val response = request<Unit>(
8282
localVariableConfig,
8383
localVariableBody
8484
)
@@ -229,7 +229,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
229229
query = localVariableQuery,
230230
headers = localVariableHeaders
231231
)
232-
val response = request<Any?>(
232+
val response = request<Unit>(
233233
localVariableConfig,
234234
localVariableBody
235235
)
@@ -253,7 +253,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
253253
* @return void
254254
*/
255255
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String, status: kotlin.String) : Unit {
256-
val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status")
256+
val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status)
257257
val localVariableQuery: MultiValueMap = mapOf()
258258

259259
val contentHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("Content-Type" to "multipart/form-data")
@@ -268,7 +268,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
268268
query = localVariableQuery,
269269
headers = localVariableHeaders
270270
)
271-
val response = request<Any?>(
271+
val response = request<Unit>(
272272
localVariableConfig,
273273
localVariableBody
274274
)
@@ -293,7 +293,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
293293
*/
294294
@Suppress("UNCHECKED_CAST")
295295
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String, file: java.io.File) : ApiResponse {
296-
val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file")
296+
val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file)
297297
val localVariableQuery: MultiValueMap = mapOf()
298298

299299
val contentHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("Content-Type" to "multipart/form-data")

samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/StoreApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
3939
query = localVariableQuery,
4040
headers = localVariableHeaders
4141
)
42-
val response = request<Any?>(
42+
val response = request<Unit>(
4343
localVariableConfig,
4444
localVariableBody
4545
)

samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/UserApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
3939
query = localVariableQuery,
4040
headers = localVariableHeaders
4141
)
42-
val response = request<Any?>(
42+
val response = request<Unit>(
4343
localVariableConfig,
4444
localVariableBody
4545
)
@@ -76,7 +76,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
7676
query = localVariableQuery,
7777
headers = localVariableHeaders
7878
)
79-
val response = request<Any?>(
79+
val response = request<Unit>(
8080
localVariableConfig,
8181
localVariableBody
8282
)
@@ -113,7 +113,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
113113
query = localVariableQuery,
114114
headers = localVariableHeaders
115115
)
116-
val response = request<Any?>(
116+
val response = request<Unit>(
117117
localVariableConfig,
118118
localVariableBody
119119
)
@@ -150,7 +150,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
150150
query = localVariableQuery,
151151
headers = localVariableHeaders
152152
)
153-
val response = request<Any?>(
153+
val response = request<Unit>(
154154
localVariableConfig,
155155
localVariableBody
156156
)
@@ -263,7 +263,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
263263
query = localVariableQuery,
264264
headers = localVariableHeaders
265265
)
266-
val response = request<Any?>(
266+
val response = request<Unit>(
267267
localVariableConfig,
268268
localVariableBody
269269
)
@@ -301,7 +301,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
301301
query = localVariableQuery,
302302
headers = localVariableHeaders
303303
)
304-
val response = request<Any?>(
304+
val response = request<Unit>(
305305
localVariableConfig,
306306
localVariableBody
307307
)

samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@ open class ApiClient(val baseUrl: String) {
3434
MediaType.parse(mediaType), content
3535
)
3636
} else if(mediaType == FormDataMediaType) {
37-
var builder = FormBody.Builder()
37+
val requestBodyBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
38+
3839
// content's type *must* be Map<String, Any>
3940
@Suppress("UNCHECKED_CAST")
40-
(content as Map<String,String>).forEach { key, value ->
41-
builder = builder.add(key, value)
41+
(content as Map<String,Any>).forEach { key, value ->
42+
if(value::class == File::class) {
43+
val file = value as File
44+
requestBodyBuilder.addFormDataPart(key, file.name, RequestBody.create(MediaType.parse("application/octet-stream"), file))
45+
} else {
46+
val stringValue = value as String
47+
requestBodyBuilder.addFormDataPart(key, stringValue)
48+
}
49+
TODO("Handle other types inside FormDataMediaType")
4250
}
43-
return builder.build()
51+
52+
return requestBodyBuilder.build()
4453
} else if(mediaType == JsonMediaType) {
4554
return RequestBody.create(
4655
MediaType.parse(mediaType), Serializer.moshi.adapter(T::class.java).toJson(content)
@@ -58,6 +67,8 @@ open class ApiClient(val baseUrl: String) {
5867

5968
if(T::class.java == java.io.File::class.java){
6069
return downloadFileFromResponse(response) as T
70+
} else if(T::class == kotlin.Unit::class) {
71+
return kotlin.Unit as T
6172
}
6273

6374
var contentType = response.headers().get("Content-Type")

samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/PetApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
4141
query = localVariableQuery,
4242
headers = localVariableHeaders
4343
)
44-
val response = request<Any?>(
44+
val response = request<Unit>(
4545
localVariableConfig,
4646
localVariableBody
4747
)
@@ -79,7 +79,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
7979
query = localVariableQuery,
8080
headers = localVariableHeaders
8181
)
82-
val response = request<Any?>(
82+
val response = request<Unit>(
8383
localVariableConfig,
8484
localVariableBody
8585
)
@@ -230,7 +230,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
230230
query = localVariableQuery,
231231
headers = localVariableHeaders
232232
)
233-
val response = request<Any?>(
233+
val response = request<Unit>(
234234
localVariableConfig,
235235
localVariableBody
236236
)
@@ -254,7 +254,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
254254
* @return void
255255
*/
256256
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String, status: kotlin.String) : Unit {
257-
val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status")
257+
val localVariableBody: kotlin.Any? = mapOf("name" to name, "status" to status)
258258
val localVariableQuery: MultiValueMap = mapOf()
259259

260260
val contentHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("Content-Type" to "multipart/form-data")
@@ -269,7 +269,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
269269
query = localVariableQuery,
270270
headers = localVariableHeaders
271271
)
272-
val response = request<Any?>(
272+
val response = request<Unit>(
273273
localVariableConfig,
274274
localVariableBody
275275
)
@@ -294,7 +294,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
294294
*/
295295
@Suppress("UNCHECKED_CAST")
296296
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String, file: java.io.File) : ApiResponse {
297-
val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file")
297+
val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to additionalMetadata, "file" to file)
298298
val localVariableQuery: MultiValueMap = mapOf()
299299

300300
val contentHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("Content-Type" to "multipart/form-data")

samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/StoreApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
4040
query = localVariableQuery,
4141
headers = localVariableHeaders
4242
)
43-
val response = request<Any?>(
43+
val response = request<Unit>(
4444
localVariableConfig,
4545
localVariableBody
4646
)

samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/UserApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
4040
query = localVariableQuery,
4141
headers = localVariableHeaders
4242
)
43-
val response = request<Any?>(
43+
val response = request<Unit>(
4444
localVariableConfig,
4545
localVariableBody
4646
)
@@ -77,7 +77,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
7777
query = localVariableQuery,
7878
headers = localVariableHeaders
7979
)
80-
val response = request<Any?>(
80+
val response = request<Unit>(
8181
localVariableConfig,
8282
localVariableBody
8383
)
@@ -114,7 +114,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
114114
query = localVariableQuery,
115115
headers = localVariableHeaders
116116
)
117-
val response = request<Any?>(
117+
val response = request<Unit>(
118118
localVariableConfig,
119119
localVariableBody
120120
)
@@ -151,7 +151,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
151151
query = localVariableQuery,
152152
headers = localVariableHeaders
153153
)
154-
val response = request<Any?>(
154+
val response = request<Unit>(
155155
localVariableConfig,
156156
localVariableBody
157157
)
@@ -264,7 +264,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
264264
query = localVariableQuery,
265265
headers = localVariableHeaders
266266
)
267-
val response = request<Any?>(
267+
val response = request<Unit>(
268268
localVariableConfig,
269269
localVariableBody
270270
)
@@ -302,7 +302,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
302302
query = localVariableQuery,
303303
headers = localVariableHeaders
304304
)
305-
val response = request<Any?>(
305+
val response = request<Unit>(
306306
localVariableConfig,
307307
localVariableBody
308308
)

samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@ open class ApiClient(val baseUrl: String) {
3434
MediaType.parse(mediaType), content
3535
)
3636
} else if(mediaType == FormDataMediaType) {
37-
var builder = FormBody.Builder()
37+
val requestBodyBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
38+
3839
// content's type *must* be Map<String, Any>
3940
@Suppress("UNCHECKED_CAST")
40-
(content as Map<String,String>).forEach { key, value ->
41-
builder = builder.add(key, value)
41+
(content as Map<String,Any>).forEach { key, value ->
42+
if(value::class == File::class) {
43+
val file = value as File
44+
requestBodyBuilder.addFormDataPart(key, file.name, RequestBody.create(MediaType.parse("application/octet-stream"), file))
45+
} else {
46+
val stringValue = value as String
47+
requestBodyBuilder.addFormDataPart(key, stringValue)
48+
}
49+
TODO("Handle other types inside FormDataMediaType")
4250
}
43-
return builder.build()
51+
52+
return requestBodyBuilder.build()
4453
} else if(mediaType == JsonMediaType) {
4554
return RequestBody.create(
4655
MediaType.parse(mediaType), Serializer.moshi.adapter(T::class.java).toJson(content)
@@ -58,6 +67,8 @@ open class ApiClient(val baseUrl: String) {
5867

5968
if(T::class.java == java.io.File::class.java){
6069
return downloadFileFromResponse(response) as T
70+
} else if(T::class == kotlin.Unit::class) {
71+
return kotlin.Unit as T
6172
}
6273

6374
var contentType = response.headers().get("Content-Type")

samples/server/petstore/kotlin-server/ktor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters.
44

5-
Generated by Swagger Codegen 2.4.0-SNAPSHOT (2018-10-21T21:30:13.105-05:00).
5+
Generated by Swagger Codegen 2.4.0-SNAPSHOT (2018-11-16T16:11:36.668+01:00).
66

77
## Requires
88

0 commit comments

Comments
 (0)