Skip to content

Commit 9bac318

Browse files
Improving Misk Kotlin Server Generator (#20973)
* first pass * fixing types * fixing action * updating samples * updating files * adding guido * fixing misk * removing old files * cleaning generated files * cleaning generated files * adding back in license
1 parent 04169ec commit 9bac318

File tree

16 files changed

+66
-59
lines changed

16 files changed

+66
-59
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ Here is a list of template creators:
11391139
* Kotlin (Spring Boot): @dr4ke616
11401140
* Kotlin (Vertx): @Wooyme
11411141
* Kotlin (JAX-RS): @anttileppa
1142-
* Kotlin Misk: @andrewwilsonnew
1142+
* Kotlin Misk: @andrewwilsonnew @guiarn
11431143
* Kotlin WireMock: @stefankoppier
11441144
* NodeJS Express: @YishTish
11451145
* PHP Flight: @daniel-sc

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

+21-14
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
5757
protected String rootPackage = "org.openapitools.server.api";
5858
protected String apiVersion = "1.0.0-SNAPSHOT";
5959

60-
@Setter
61-
protected String moduleClassName = "OpenApiModule";
60+
@Setter protected String moduleClassName = "OpenApiModule";
6261

6362
@Override
6463
public CodegenType getTag() {
@@ -122,7 +121,7 @@ public KotlinMiskServerCodegen() {
122121
supportingFiles.clear();
123122

124123
apiTemplateFiles.clear();
125-
apiTemplateFiles.put("apiController.mustache", "Controller.kt");
124+
apiTemplateFiles.put("apiAction.mustache", "Action.kt");
126125
apiTemplateFiles.put("apiImpl.mustache", "Impl.kt");
127126
apiTemplateFiles.put("apiInterface.mustache", ".kt");
128127
modelTemplateFiles.put("model.mustache", ".kt");
@@ -199,30 +198,38 @@ public boolean getUseBeanValidation() {
199198
}
200199

201200
private String mapMediaType(String mediaType) {
202-
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> " + mediaType + " */ ");
201+
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* @todo(unknown) -> " + mediaType + " */ ");
203202
}
204203

205204
private final static Map<String, String> MEDIA_MAPPING = getMappings();
206205

207206
private static Map<String, String> getMappings() {
207+
// add new values in order
208208
Map<String, String> result = new HashMap<>();
209-
result.put("application/json", "MediaTypes.APPLICATION_JSON");
210-
result.put("application/xml", "MediaTypes.APPLICATION_XML");
211-
result.put("application/javascript", "MediaTypes.APPLICATION_JAVASCRIPT");
212209
result.put("*/*", "MediaTypes.ALL");
213-
result.put("application/x-www-form-urlencoded", "MediaTypes.APPLICATION_FORM_URLENCODED");
210+
211+
result.put("application/grpc", "MediaTypes.APPLICATION_GRPC");
212+
result.put("application/javascript", "MediaTypes.APPLICATION_JAVASCRIPT");
213+
result.put("application/json", "MediaTypes.APPLICATION_JSON");
214214
result.put("application/octetstream", "MediaTypes.APPLICATION_OCTETSTREAM");
215215
result.put("application/pdf", "MediaTypes.APPLICATION_OCTETSTREAM");
216216
result.put("application/x-protobuf", "MediaTypes.APPLICATION_PROTOBUF");
217-
result.put("application/grpc", "MediaTypes.APPLICATION_GRPC");
218-
result.put("text/css", "MediaTypes.TEXT_CSS");
219-
result.put("text/html", "MediaTypes.TEXT_HTML");
220-
result.put("text/plain", "MediaTypes.TEXT_PLAIN_UTF8");
217+
result.put("application/x-www-form-urlencoded", "MediaTypes.APPLICATION_FORM_URLENCODED");
218+
result.put("application/xml", "MediaTypes.APPLICATION_XML");
219+
result.put("application/zip", "MediaTypes.APPLICATION_ZIP");
220+
221+
result.put("image/gif", "MediaTypes.IMAGE_GIF");
222+
result.put("image/jpeg", "MediaTypes.IMAGE_JPEG");
221223
result.put("image/png", "MediaTypes.IMAGE_PNG");
222224
result.put("image/svg+xml", "MediaTypes.IMAGE_SVG");
223-
result.put("image/jpeg", "MediaTypes.IMAGE_JPEG");
224-
result.put("image/gif", "MediaTypes.IMAGE_GIF");
225225
result.put("image/x-icon", "MediaTypes.IMAGE_ICO");
226+
227+
result.put("multipart/form-data", "MediaTypes.FORM_DATA");
228+
229+
result.put("text/css", "MediaTypes.TEXT_CSS");
230+
result.put("text/html", "MediaTypes.TEXT_HTML");
231+
result.put("text/plain", "MediaTypes.TEXT_PLAIN_UTF8");
232+
226233
return result;
227234
}
228235
}

Diff for: modules/openapi-generator/src/main/resources/kotlin-misk/apiController.mustache renamed to modules/openapi-generator/src/main/resources/kotlin-misk/apiAction.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import misk.web.mediatype.MediaTypes
3434

3535
{{#operations}}
3636
/**
37-
* Generated file, please change {{classname}}Controller.
37+
* Generated file, please change {{classname}}Impl.
3838
*/
3939
@Singleton
40-
class {{classname}}Controller @Inject constructor(
40+
class {{classname}}Action @Inject constructor(
4141
private val {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}
4242
) : WebAction, {{classname}} {
4343
{{#operation}}

Diff for: modules/openapi-generator/src/main/resources/kotlin-misk/api_test.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class {{classname}}Test {
2121
{{#operations}}
2222
{{#operation}}
2323
/**
24-
* To test {{classname}}Controller.{{operationId}}
24+
* To test {{classname}}Action.{{operationId}}
2525
*/
2626
@Test
2727
fun `should handle {{operationId}}`() {

Diff for: modules/openapi-generator/src/main/resources/kotlin-misk/build.gradle.kts.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version = "{{artifactVersion}}"
99

1010
dependencies {
1111
implementation("jakarta.validation:jakarta.validation-api:3.1.1")
12-
implementation("com.squareup.misk:misk:2025.03.17.160337-2c6953c")
12+
implementation("com.squareup.misk:misk:2025.04.02.195630-a61d550")
1313
//implementation("com.squareup.wire:wire-runtime:5.2.1")
1414
1515
testImplementation("com.squareup.misk:misk-testing:2025.02.11.123913-8a41324")

Diff for: modules/openapi-generator/src/main/resources/kotlin-misk/miskModule.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {{javaxPackage}}.inject.Singleton
66
{{#apiInfo}}
77
{{#apis}}
88
{{#operations}}
9-
import {{apiPackage}}.{{classname}}Controller
9+
import {{apiPackage}}.{{classname}}Action
1010
{{/operations}}
1111
{{/apis}}
1212
{{/apiInfo}}
@@ -17,7 +17,7 @@ class {{moduleClassName}} : KAbstractModule() {
1717
{{#apiInfo}}
1818
{{#apis}}
1919
{{#operations}}
20-
install(WebActionModule.create<{{classname}}Controller>())
20+
install(WebActionModule.create<{{classname}}Action>())
2121
{{/operations}}
2222
{{/apis}}
2323
{{/apiInfo}}

Diff for: samples/server/petstore/kotlin-misk/.openapi-generator/FILES

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ docs/User.md
1111
docs/UserApi.md
1212
settings.gradle.kts
1313
src/main/kotlin/org/openapitools/server/api/api/PetApi.kt
14-
src/main/kotlin/org/openapitools/server/api/api/PetApiController.kt
14+
src/main/kotlin/org/openapitools/server/api/api/PetApiAction.kt
1515
src/main/kotlin/org/openapitools/server/api/api/PetApiImpl.kt
1616
src/main/kotlin/org/openapitools/server/api/api/PetStoreModule.kt
1717
src/main/kotlin/org/openapitools/server/api/api/StoreApi.kt
18-
src/main/kotlin/org/openapitools/server/api/api/StoreApiController.kt
18+
src/main/kotlin/org/openapitools/server/api/api/StoreApiAction.kt
1919
src/main/kotlin/org/openapitools/server/api/api/StoreApiImpl.kt
2020
src/main/kotlin/org/openapitools/server/api/api/UserApi.kt
21-
src/main/kotlin/org/openapitools/server/api/api/UserApiController.kt
21+
src/main/kotlin/org/openapitools/server/api/api/UserApiAction.kt
2222
src/main/kotlin/org/openapitools/server/api/api/UserApiImpl.kt
2323
src/main/kotlin/org/openapitools/server/api/model/Category.kt
2424
src/main/kotlin/org/openapitools/server/api/model/ModelApiResponse.kt

Diff for: samples/server/petstore/kotlin-misk/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version = "1.0.0-SNAPSHOT"
99

1010
dependencies {
1111
implementation("jakarta.validation:jakarta.validation-api:3.1.1")
12-
implementation("com.squareup.misk:misk:2025.03.17.160337-2c6953c")
12+
implementation("com.squareup.misk:misk:2025.04.02.195630-a61d550")
1313
//implementation("com.squareup.wire:wire-runtime:5.2.1")
1414

1515
testImplementation("com.squareup.misk:misk-testing:2025.02.11.123913-8a41324")

Diff for: samples/server/petstore/kotlin-misk/docs/PetApi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,6 @@ Name | Type | Description | Notes
395395

396396
### HTTP request headers
397397

398-
- **Content-Type**: MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */
398+
- **Content-Type**: MediaTypes.FORM_DATA
399399
- **Accept**: MediaTypes.APPLICATION_JSON
400400

Diff for: samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetApiController.kt renamed to samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetApiAction.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import org.openapitools.server.api.model.ModelApiResponse
3131
import org.openapitools.server.api.model.Pet
3232

3333
/**
34-
* Generated file, please change PetApiController.
34+
* Generated file, please change PetApiImpl.
3535
*/
3636
@Singleton
37-
class PetApiController @Inject constructor(
37+
class PetApiAction @Inject constructor(
3838
private val petApi: PetApi
3939
) : WebAction, PetApi {
4040

@@ -97,7 +97,7 @@ class PetApiController @Inject constructor(
9797

9898
@Post("/pet/{petId}/uploadImage")
9999
@Description("uploads an image")
100-
@RequestContentType(MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */ )
100+
@RequestContentType(MediaTypes.FORM_DATA)
101101
@ResponseContentType(MediaTypes.APPLICATION_JSON)
102102
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
103103
override fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {

Diff for: samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetStoreModule.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package org.openapitools.server.api.api
33
import misk.inject.KAbstractModule
44
import misk.web.WebActionModule
55
import jakarta.inject.Singleton
6-
import org.openapitools.server.api.api.PetApiController
7-
import org.openapitools.server.api.api.StoreApiController
8-
import org.openapitools.server.api.api.UserApiController
6+
import org.openapitools.server.api.api.PetApiAction
7+
import org.openapitools.server.api.api.StoreApiAction
8+
import org.openapitools.server.api.api.UserApiAction
99

1010
@Singleton
1111
class PetStoreModule : KAbstractModule() {
1212
override fun configure() {
13-
install(WebActionModule.create<PetApiController>())
14-
install(WebActionModule.create<StoreApiController>())
15-
install(WebActionModule.create<UserApiController>())
13+
install(WebActionModule.create<PetApiAction>())
14+
install(WebActionModule.create<StoreApiAction>())
15+
install(WebActionModule.create<UserApiAction>())
1616
}
1717
}

Diff for: samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/StoreApiController.kt renamed to samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/StoreApiAction.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import misk.web.mediatype.MediaTypes
3030
import org.openapitools.server.api.model.Order
3131

3232
/**
33-
* Generated file, please change StoreApiController.
33+
* Generated file, please change StoreApiImpl.
3434
*/
3535
@Singleton
36-
class StoreApiController @Inject constructor(
36+
class StoreApiAction @Inject constructor(
3737
private val storeApi: StoreApi
3838
) : WebAction, StoreApi {
3939

Diff for: samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/UserApiController.kt renamed to samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/UserApiAction.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import misk.web.mediatype.MediaTypes
3030
import org.openapitools.server.api.model.User
3131

3232
/**
33-
* Generated file, please change UserApiController.
33+
* Generated file, please change UserApiImpl.
3434
*/
3535
@Singleton
36-
class UserApiController @Inject constructor(
36+
class UserApiAction @Inject constructor(
3737
private val userApi: UserApi
3838
) : WebAction, UserApi {
3939

Diff for: samples/server/petstore/kotlin-misk/src/test/kotlin/org/openapitools/server/api/api/PetApiTest.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class PetApiTest {
1919
@Inject private lateinit var petApi: PetApi
2020

2121
/**
22-
* To test PetApiController.addPet
22+
* To test PetApiAction.addPet
2323
*/
2424
@Test
2525
fun `should handle addPet`() {
@@ -28,7 +28,7 @@ internal class PetApiTest {
2828
}
2929

3030
/**
31-
* To test PetApiController.deletePet
31+
* To test PetApiAction.deletePet
3232
*/
3333
@Test
3434
fun `should handle deletePet`() {
@@ -38,7 +38,7 @@ internal class PetApiTest {
3838
}
3939

4040
/**
41-
* To test PetApiController.findPetsByStatus
41+
* To test PetApiAction.findPetsByStatus
4242
*/
4343
@Test
4444
fun `should handle findPetsByStatus`() {
@@ -47,7 +47,7 @@ internal class PetApiTest {
4747
}
4848

4949
/**
50-
* To test PetApiController.findPetsByTags
50+
* To test PetApiAction.findPetsByTags
5151
*/
5252
@Test
5353
fun `should handle findPetsByTags`() {
@@ -56,7 +56,7 @@ internal class PetApiTest {
5656
}
5757

5858
/**
59-
* To test PetApiController.getPetById
59+
* To test PetApiAction.getPetById
6060
*/
6161
@Test
6262
fun `should handle getPetById`() {
@@ -65,7 +65,7 @@ internal class PetApiTest {
6565
}
6666

6767
/**
68-
* To test PetApiController.updatePet
68+
* To test PetApiAction.updatePet
6969
*/
7070
@Test
7171
fun `should handle updatePet`() {
@@ -74,7 +74,7 @@ internal class PetApiTest {
7474
}
7575

7676
/**
77-
* To test PetApiController.updatePetWithForm
77+
* To test PetApiAction.updatePetWithForm
7878
*/
7979
@Test
8080
fun `should handle updatePetWithForm`() {
@@ -85,7 +85,7 @@ internal class PetApiTest {
8585
}
8686

8787
/**
88-
* To test PetApiController.uploadFile
88+
* To test PetApiAction.uploadFile
8989
*/
9090
@Test
9191
fun `should handle uploadFile`() {

Diff for: samples/server/petstore/kotlin-misk/src/test/kotlin/org/openapitools/server/api/api/StoreApiTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class StoreApiTest {
1818
@Inject private lateinit var storeApi: StoreApi
1919

2020
/**
21-
* To test StoreApiController.deleteOrder
21+
* To test StoreApiAction.deleteOrder
2222
*/
2323
@Test
2424
fun `should handle deleteOrder`() {
@@ -27,15 +27,15 @@ internal class StoreApiTest {
2727
}
2828

2929
/**
30-
* To test StoreApiController.getInventory
30+
* To test StoreApiAction.getInventory
3131
*/
3232
@Test
3333
fun `should handle getInventory`() {
3434
val response: kotlin.collections.Map<kotlin.String, kotlin.Int> = storeApi.getInventory()
3535
}
3636

3737
/**
38-
* To test StoreApiController.getOrderById
38+
* To test StoreApiAction.getOrderById
3939
*/
4040
@Test
4141
fun `should handle getOrderById`() {
@@ -44,7 +44,7 @@ internal class StoreApiTest {
4444
}
4545

4646
/**
47-
* To test StoreApiController.placeOrder
47+
* To test StoreApiAction.placeOrder
4848
*/
4949
@Test
5050
fun `should handle placeOrder`() {

0 commit comments

Comments
 (0)