Skip to content

Commit 4402d83

Browse files
Fix MiskKotlin OpenApiGenerator types (#21390)
* first pass * fixup up Array -> List * fixup up Array -> List * File response type * don't mess returnTypes.mustache
1 parent 89eea74 commit 4402d83

File tree

19 files changed

+137
-85
lines changed

19 files changed

+137
-85
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinMiskServerCodegen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public KotlinMiskServerCodegen() {
172172
artifactId = "openapi-kotlin-misk-server";
173173
artifactVersion = apiVersion;
174174

175+
typeMapping.put("array", "kotlin.collections.List");
176+
175177
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
176178
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
177179
additionalProperties.put(ROOT_PACKAGE, rootPackage);
@@ -328,4 +330,4 @@ private static Map<String, String> getMappings() {
328330

329331
return result;
330332
}
331-
}
333+
}

modules/openapi-generator/src/main/resources/kotlin-misk/apiAction.mustache

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import misk.web.QueryParam
2828
import misk.web.RequestBody
2929
import misk.web.RequestContentType
3030
import misk.web.RequestHeader
31+
import misk.web.Response
3132
import misk.web.ResponseContentType
3233
import misk.web.mediatype.MediaTypes
3334
{{#imports}}
@@ -50,10 +51,13 @@ class {{classname}}Action @Inject constructor(
5051
{{#actionAnnotations}}
5152
{{{.}}}
5253
{{/actionAnnotations}}
53-
fun {{operationId}}({{#allParams}}
54-
{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
54+
fun {{operationId}}(
55+
{{#allParams}}
56+
{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}
57+
{{/allParams}}
58+
): {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response<Unit>{{/returnType}} {
5559
TODO()
5660
}
5761
{{/operation}}
5862
}
59-
{{/operations}}
63+
{{/operations}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{^isFile}}{{{dataType}}}{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{/isFile}}{{#isFile}}{{#isArray}}Array<{{/isArray}}{{#isArray}}>{{/isArray}}{{^isArray}}{{^required}}{{/required}}{{/isArray}}{{/isFile}}
1+
{{^isFile}}{{{dataType}}}{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{/isFile}}{{#isFile}}{{#isArray}}kotlin.collections.List<{{/isArray}}{{#isArray}}>{{/isArray}}{{^isArray}}{{^required}}{{/required}}{{/isArray}}{{/isFile}}

samples/server/petstore/kotlin-misk-config/docs/Pet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**name** | **kotlin.String** | |
8-
**photoUrls** | **kotlin.Array&lt;kotlin.String&gt;** | |
8+
**photoUrls** | **kotlin.collections.List&lt;kotlin.String&gt;** | |
99
**id** | **kotlin.Long** | | [optional]
1010
**category** | [**Category**](Category.md) | | [optional]
11-
**tags** | [**kotlin.Array&lt;Tag&gt;**](Tag.md) | | [optional]
11+
**tags** | [**kotlin.collections.List&lt;Tag&gt;**](Tag.md) | | [optional]
1212
**status** | [**inline**](#Status) | pet status in the store | [optional]
1313

1414

samples/server/petstore/kotlin-misk-config/docs/PetApi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ null (empty response body)
111111

112112
<a name="findPetsByStatus"></a>
113113
# **findPetsByStatus**
114-
> kotlin.Array&lt;Pet&gt; findPetsByStatus(status)
114+
> kotlin.collections.List&lt;Pet&gt; findPetsByStatus(status)
115115
116116
Finds Pets by status
117117

@@ -124,9 +124,9 @@ Multiple status values can be provided with comma separated strings
124124
//import org.openapitools.server.api.model.*
125125

126126
val apiInstance = PetApi()
127-
val status : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> | Status values that need to be considered for filter
127+
val status : kotlin.collections.List<kotlin.String> = // kotlin.collections.List<kotlin.String> | Status values that need to be considered for filter
128128
try {
129-
val result : kotlin.Array<Pet> = apiInstance.findPetsByStatus(status)
129+
val result : kotlin.collections.List<Pet> = apiInstance.findPetsByStatus(status)
130130
println(result)
131131
} catch (e: ClientException) {
132132
println("4xx response calling PetApi#findPetsByStatus")
@@ -141,11 +141,11 @@ try {
141141

142142
Name | Type | Description | Notes
143143
------------- | ------------- | ------------- | -------------
144-
**status** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| Status values that need to be considered for filter | [enum: available, pending, sold]
144+
**status** | [**kotlin.collections.List&lt;kotlin.String&gt;**](kotlin.String.md)| Status values that need to be considered for filter | [enum: available, pending, sold]
145145

146146
### Return type
147147

148-
[**kotlin.Array&lt;Pet&gt;**](Pet.md)
148+
[**kotlin.collections.List&lt;Pet&gt;**](Pet.md)
149149

150150
### Authorization
151151

@@ -158,7 +158,7 @@ Name | Type | Description | Notes
158158

159159
<a name="findPetsByTags"></a>
160160
# **findPetsByTags**
161-
> kotlin.Array&lt;Pet&gt; findPetsByTags(tags)
161+
> kotlin.collections.List&lt;Pet&gt; findPetsByTags(tags)
162162
163163
Finds Pets by tags
164164

@@ -171,9 +171,9 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
171171
//import org.openapitools.server.api.model.*
172172

173173
val apiInstance = PetApi()
174-
val tags : kotlin.Array<kotlin.String> = // kotlin.Array<kotlin.String> | Tags to filter by
174+
val tags : kotlin.collections.List<kotlin.String> = // kotlin.collections.List<kotlin.String> | Tags to filter by
175175
try {
176-
val result : kotlin.Array<Pet> = apiInstance.findPetsByTags(tags)
176+
val result : kotlin.collections.List<Pet> = apiInstance.findPetsByTags(tags)
177177
println(result)
178178
} catch (e: ClientException) {
179179
println("4xx response calling PetApi#findPetsByTags")
@@ -188,11 +188,11 @@ try {
188188

189189
Name | Type | Description | Notes
190190
------------- | ------------- | ------------- | -------------
191-
**tags** | [**kotlin.Array&lt;kotlin.String&gt;**](kotlin.String.md)| Tags to filter by |
191+
**tags** | [**kotlin.collections.List&lt;kotlin.String&gt;**](kotlin.String.md)| Tags to filter by |
192192

193193
### Return type
194194

195-
[**kotlin.Array&lt;Pet&gt;**](Pet.md)
195+
[**kotlin.collections.List&lt;Pet&gt;**](Pet.md)
196196

197197
### Authorization
198198

samples/server/petstore/kotlin-misk-config/docs/UserApi.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Creates list of users with given input array
7575
//import org.openapitools.server.api.model.*
7676

7777
val apiInstance = UserApi()
78-
val user : kotlin.Array<User> = // kotlin.Array<User> | List of user object
78+
val user : kotlin.collections.List<User> = // kotlin.collections.List<User> | List of user object
7979
try {
8080
apiInstance.createUsersWithArrayInput(user)
8181
} catch (e: ClientException) {
@@ -91,7 +91,7 @@ try {
9191

9292
Name | Type | Description | Notes
9393
------------- | ------------- | ------------- | -------------
94-
**user** | [**kotlin.Array&lt;User&gt;**](User.md)| List of user object |
94+
**user** | [**kotlin.collections.List&lt;User&gt;**](User.md)| List of user object |
9595

9696
### Return type
9797

@@ -121,7 +121,7 @@ Creates list of users with given input array
121121
//import org.openapitools.server.api.model.*
122122

123123
val apiInstance = UserApi()
124-
val user : kotlin.Array<User> = // kotlin.Array<User> | List of user object
124+
val user : kotlin.collections.List<User> = // kotlin.collections.List<User> | List of user object
125125
try {
126126
apiInstance.createUsersWithListInput(user)
127127
} catch (e: ClientException) {
@@ -137,7 +137,7 @@ try {
137137

138138
Name | Type | Description | Notes
139139
------------- | ------------- | ------------- | -------------
140-
**user** | [**kotlin.Array&lt;User&gt;**](User.md)| List of user object |
140+
**user** | [**kotlin.collections.List&lt;User&gt;**](User.md)| List of user object |
141141

142142
### Return type
143143

samples/server/petstore/kotlin-misk-config/src/main/kotlin/org/openapitools/server/api/api/PetApiAction.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import misk.web.QueryParam
2525
import misk.web.RequestBody
2626
import misk.web.RequestContentType
2727
import misk.web.RequestHeader
28+
import misk.web.Response
2829
import misk.web.ResponseContentType
2930
import misk.web.mediatype.MediaTypes
3031
import org.openapitools.server.api.model.ModelApiResponse
@@ -44,7 +45,8 @@ class PetApiAction @Inject constructor(
4445
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
4546
@Suppress("unused")
4647
fun addPet(
47-
@Valid @RequestBody pet: Pet): Pet {
48+
@Valid @RequestBody pet: Pet
49+
): Pet {
4850
TODO()
4951
}
5052

@@ -54,7 +56,8 @@ class PetApiAction @Inject constructor(
5456
@Suppress("unused")
5557
fun deletePet(
5658
@PathParam("petId") petId: kotlin.Long,
57-
@RequestHeader(value = "api_key") apiKey: kotlin.String?) {
59+
@RequestHeader(value = "api_key") apiKey: kotlin.String?
60+
): Response<Unit> {
5861
TODO()
5962
}
6063

@@ -64,7 +67,8 @@ class PetApiAction @Inject constructor(
6467
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
6568
@Suppress("unused")
6669
fun findPetsByStatus(
67-
@QueryParam(value = "status") status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
70+
@QueryParam(value = "status") status: kotlin.collections.List<kotlin.String>
71+
): kotlin.collections.List<Pet> {
6872
TODO()
6973
}
7074

@@ -74,7 +78,8 @@ class PetApiAction @Inject constructor(
7478
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
7579
@Suppress("unused")
7680
fun findPetsByTags(
77-
@QueryParam(value = "tags") tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
81+
@QueryParam(value = "tags") tags: kotlin.collections.List<kotlin.String>
82+
): kotlin.collections.List<Pet> {
7883
TODO()
7984
}
8085

@@ -84,7 +89,8 @@ class PetApiAction @Inject constructor(
8489
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
8590
@Suppress("unused")
8691
fun getPetById(
87-
@PathParam("petId") petId: kotlin.Long): Pet {
92+
@PathParam("petId") petId: kotlin.Long
93+
): Pet {
8894
TODO()
8995
}
9096

@@ -95,7 +101,8 @@ class PetApiAction @Inject constructor(
95101
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
96102
@Suppress("unused")
97103
fun updatePet(
98-
@Valid @RequestBody pet: Pet): Pet {
104+
@Valid @RequestBody pet: Pet
105+
): Pet {
99106
TODO()
100107
}
101108

@@ -107,7 +114,8 @@ class PetApiAction @Inject constructor(
107114
fun updatePetWithForm(
108115
@PathParam("petId") petId: kotlin.Long,
109116
@QueryParam(value = "name") name: kotlin.String? ,
110-
@QueryParam(value = "status") status: kotlin.String? ) {
117+
@QueryParam(value = "status") status: kotlin.String?
118+
): Response<Unit> {
111119
TODO()
112120
}
113121

@@ -120,7 +128,8 @@ class PetApiAction @Inject constructor(
120128
fun uploadFile(
121129
@PathParam("petId") petId: kotlin.Long,
122130
@QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? ,
123-
@Valid file: HttpCall): ModelApiResponse {
131+
@Valid file: HttpCall
132+
): ModelApiResponse {
124133
TODO()
125134
}
126135
}

samples/server/petstore/kotlin-misk-config/src/main/kotlin/org/openapitools/server/api/api/StoreApiAction.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import misk.web.QueryParam
2525
import misk.web.RequestBody
2626
import misk.web.RequestContentType
2727
import misk.web.RequestHeader
28+
import misk.web.Response
2829
import misk.web.ResponseContentType
2930
import misk.web.mediatype.MediaTypes
3031
import org.openapitools.server.api.model.Order
@@ -41,7 +42,8 @@ class StoreApiAction @Inject constructor(
4142
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
4243
@Suppress("unused")
4344
fun deleteOrder(
44-
@PathParam("orderId") orderId: kotlin.String) {
45+
@PathParam("orderId") orderId: kotlin.String
46+
): Response<Unit> {
4547
TODO()
4648
}
4749

@@ -50,7 +52,8 @@ class StoreApiAction @Inject constructor(
5052
@ResponseContentType(MediaTypes.APPLICATION_JSON)
5153
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
5254
@Suppress("unused")
53-
fun getInventory(): kotlin.collections.Map<kotlin.String, kotlin.Int> {
55+
fun getInventory(
56+
): kotlin.collections.Map<kotlin.String, kotlin.Int> {
5457
TODO()
5558
}
5659

@@ -60,7 +63,8 @@ class StoreApiAction @Inject constructor(
6063
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
6164
@Suppress("unused")
6265
fun getOrderById(
63-
@Min(1L) @Max(5L) @PathParam("orderId") orderId: kotlin.Long): Order {
66+
@Min(1L) @Max(5L) @PathParam("orderId") orderId: kotlin.Long
67+
): Order {
6468
TODO()
6569
}
6670

@@ -71,7 +75,8 @@ class StoreApiAction @Inject constructor(
7175
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
7276
@Suppress("unused")
7377
fun placeOrder(
74-
@Valid @RequestBody order: Order): Order {
78+
@Valid @RequestBody order: Order
79+
): Order {
7580
TODO()
7681
}
7782
}

samples/server/petstore/kotlin-misk-config/src/main/kotlin/org/openapitools/server/api/api/UserApiAction.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import misk.web.QueryParam
2525
import misk.web.RequestBody
2626
import misk.web.RequestContentType
2727
import misk.web.RequestHeader
28+
import misk.web.Response
2829
import misk.web.ResponseContentType
2930
import misk.web.mediatype.MediaTypes
3031
import org.openapitools.server.api.model.User
@@ -42,7 +43,8 @@ class UserApiAction @Inject constructor(
4243
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
4344
@Suppress("unused")
4445
fun createUser(
45-
@Valid @RequestBody user: User) {
46+
@Valid @RequestBody user: User
47+
): Response<Unit> {
4648
TODO()
4749
}
4850

@@ -52,7 +54,8 @@ class UserApiAction @Inject constructor(
5254
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
5355
@Suppress("unused")
5456
fun createUsersWithArrayInput(
55-
@Valid @RequestBody user: kotlin.Array<User>) {
57+
@Valid @RequestBody user: kotlin.collections.List<User>
58+
): Response<Unit> {
5659
TODO()
5760
}
5861

@@ -62,7 +65,8 @@ class UserApiAction @Inject constructor(
6265
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
6366
@Suppress("unused")
6467
fun createUsersWithListInput(
65-
@Valid @RequestBody user: kotlin.Array<User>) {
68+
@Valid @RequestBody user: kotlin.collections.List<User>
69+
): Response<Unit> {
6670
TODO()
6771
}
6872

@@ -71,7 +75,8 @@ class UserApiAction @Inject constructor(
7175
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
7276
@Suppress("unused")
7377
fun deleteUser(
74-
@PathParam("username") username: kotlin.String) {
78+
@PathParam("username") username: kotlin.String
79+
): Response<Unit> {
7580
TODO()
7681
}
7782

@@ -81,7 +86,8 @@ class UserApiAction @Inject constructor(
8186
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
8287
@Suppress("unused")
8388
fun getUserByName(
84-
@PathParam("username") username: kotlin.String): User {
89+
@PathParam("username") username: kotlin.String
90+
): User {
8591
TODO()
8692
}
8793

@@ -92,15 +98,17 @@ class UserApiAction @Inject constructor(
9298
@Suppress("unused")
9399
fun loginUser(
94100
@QueryParam(value = "username") username: kotlin.String,
95-
@QueryParam(value = "password") password: kotlin.String): kotlin.String {
101+
@QueryParam(value = "password") password: kotlin.String
102+
): kotlin.String {
96103
TODO()
97104
}
98105

99106
@Get("samplePrefix/user/logout")
100107
@Description("Logs out current logged in user session")
101108
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 2.0)
102109
@Suppress("unused")
103-
fun logoutUser() {
110+
fun logoutUser(
111+
): Response<Unit> {
104112
TODO()
105113
}
106114

@@ -111,7 +119,8 @@ class UserApiAction @Inject constructor(
111119
@Suppress("unused")
112120
fun updateUser(
113121
@PathParam("username") username: kotlin.String,
114-
@Valid @RequestBody user: User) {
122+
@Valid @RequestBody user: User
123+
): Response<Unit> {
115124
TODO()
116125
}
117126
}

0 commit comments

Comments
 (0)