Skip to content

Commit 6605164

Browse files
author
andrewwilsonnew
committed
add action prefix
1 parent e5ef191 commit 6605164

7 files changed

Lines changed: 32 additions & 22 deletions

File tree

bin/configs/kotlin-misk-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ additionalProperties:
77
hideGenerationTimestamp: "true"
88
moduleClassName: "PetStoreModule"
99
generateStubImplClasses: true
10-
addModelMoshiJsonAnnotation: true
10+
addModelMoshiJsonAnnotation: true
11+
actionPrefix : "samplePrefix"

docs/generators/kotlin-misk.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1818

1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
21+
|actionPrefix|Prefix for all action| | null |
2122
|addModelMoshiJsonAnnotation|Add a Moshi JSON adapter annotation to all model classes| |true|
2223
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
2324
|apiSuffix|suffix for api classes| |Api|

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
5050
private final Logger LOGGER = LoggerFactory.getLogger(KotlinMiskServerCodegen.class);
5151

5252
public static final String MODULE_CLASS_NAME = "moduleClassName";
53+
public static final String ACTION_PREFIX = "actionPrefix";
5354

5455
private static final String ROOT_PACKAGE = "rootPackage";
5556
public static final String GENERATE_STUB_IMPL_CLASSES = "generateStubImplClasses";
@@ -67,6 +68,7 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
6768
protected String apiVersion = "1.0.0-SNAPSHOT";
6869

6970
@Setter protected String moduleClassName = "OpenApiModule";
71+
@Setter protected String actionPrefix = "";
7072

7173
@Override
7274
public CodegenType getTag() {
@@ -119,6 +121,7 @@ public KotlinMiskServerCodegen() {
119121
outputFolder = "generated-code" + File.separator + "kotlin-misk";
120122

121123
addOption(MODULE_CLASS_NAME, "Name of the generated module class", moduleClassName);
124+
addOption(ACTION_PREFIX, "Prefix for all action", actionPrefix);
122125

123126
apiTestTemplateFiles.clear();
124127
apiTestTemplateFiles.put("api_test.mustache", ".kt");
@@ -165,6 +168,11 @@ public void processOpts() {
165168
}
166169
additionalProperties.put(MODULE_CLASS_NAME, moduleClassName);
167170

171+
if (additionalProperties.containsKey(ACTION_PREFIX)) {
172+
setActionPrefix((String) additionalProperties.get(ACTION_PREFIX));
173+
}
174+
additionalProperties.put(ACTION_PREFIX, actionPrefix);
175+
168176
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
169177
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
170178
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class {{classname}}Action @Inject constructor(
4141
) : WebAction {
4242
{{#operation}}
4343

44-
@{{httpMethod}}("{{path}}")
44+
@{{httpMethod}}("{{actionPrefix}}{{path}}")
4545
@Description("{{{summary}}}"){{#hasConsumes}}
4646
@RequestContentType({{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}){{/hasConsumes}}{{#hasProduces}}
4747
@ResponseContentType({{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}){{/hasProduces}}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.openapitools.server.api.model.Pet
3737
class PetApiAction @Inject constructor(
3838
) : WebAction {
3939

40-
@Post("/pet")
40+
@Post("samplePrefix/pet")
4141
@Description("Add a new pet to the store")
4242
@RequestContentType(MediaTypes.APPLICATION_JSON, MediaTypes.APPLICATION_XML)
4343
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
@@ -47,7 +47,7 @@ class PetApiAction @Inject constructor(
4747
TODO()
4848
}
4949

50-
@Delete("/pet/{petId}")
50+
@Delete("samplePrefix/pet/{petId}")
5151
@Description("Deletes a pet")
5252
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
5353
fun deletePet(
@@ -56,7 +56,7 @@ class PetApiAction @Inject constructor(
5656
TODO()
5757
}
5858

59-
@Get("/pet/findByStatus")
59+
@Get("samplePrefix/pet/findByStatus")
6060
@Description("Finds Pets by status")
6161
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
6262
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -65,7 +65,7 @@ class PetApiAction @Inject constructor(
6565
TODO()
6666
}
6767

68-
@Get("/pet/findByTags")
68+
@Get("samplePrefix/pet/findByTags")
6969
@Description("Finds Pets by tags")
7070
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
7171
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -74,7 +74,7 @@ class PetApiAction @Inject constructor(
7474
TODO()
7575
}
7676

77-
@Get("/pet/{petId}")
77+
@Get("samplePrefix/pet/{petId}")
7878
@Description("Find pet by ID")
7979
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
8080
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -83,7 +83,7 @@ class PetApiAction @Inject constructor(
8383
TODO()
8484
}
8585

86-
@Put("/pet")
86+
@Put("samplePrefix/pet")
8787
@Description("Update an existing pet")
8888
@RequestContentType(MediaTypes.APPLICATION_JSON, MediaTypes.APPLICATION_XML)
8989
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
@@ -93,7 +93,7 @@ class PetApiAction @Inject constructor(
9393
TODO()
9494
}
9595

96-
@Post("/pet/{petId}")
96+
@Post("samplePrefix/pet/{petId}")
9797
@Description("Updates a pet in the store with form data")
9898
@RequestContentType(MediaTypes.APPLICATION_FORM_URLENCODED)
9999
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -104,7 +104,7 @@ class PetApiAction @Inject constructor(
104104
TODO()
105105
}
106106

107-
@Post("/pet/{petId}/uploadImage")
107+
@Post("samplePrefix/pet/{petId}/uploadImage")
108108
@Description("uploads an image")
109109
@RequestContentType(MediaTypes.FORM_DATA)
110110
@ResponseContentType(MediaTypes.APPLICATION_JSON)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ import org.openapitools.server.api.model.Order
3636
class StoreApiAction @Inject constructor(
3737
) : WebAction {
3838

39-
@Delete("/store/order/{orderId}")
39+
@Delete("samplePrefix/store/order/{orderId}")
4040
@Description("Delete purchase order by ID")
4141
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
4242
fun deleteOrder(
4343
@PathParam("orderId") orderId: kotlin.String) {
4444
TODO()
4545
}
4646

47-
@Get("/store/inventory")
47+
@Get("samplePrefix/store/inventory")
4848
@Description("Returns pet inventories by status")
4949
@ResponseContentType(MediaTypes.APPLICATION_JSON)
5050
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
5151
fun getInventory(): kotlin.collections.Map<kotlin.String, kotlin.Int> {
5252
TODO()
5353
}
5454

55-
@Get("/store/order/{orderId}")
55+
@Get("samplePrefix/store/order/{orderId}")
5656
@Description("Find purchase order by ID")
5757
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
5858
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -61,7 +61,7 @@ class StoreApiAction @Inject constructor(
6161
TODO()
6262
}
6363

64-
@Post("/store/order")
64+
@Post("samplePrefix/store/order")
6565
@Description("Place an order for a pet")
6666
@RequestContentType(MediaTypes.APPLICATION_JSON)
6767
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import org.openapitools.server.api.model.User
3636
class UserApiAction @Inject constructor(
3737
) : WebAction {
3838

39-
@Post("/user")
39+
@Post("samplePrefix/user")
4040
@Description("Create user")
4141
@RequestContentType(MediaTypes.APPLICATION_JSON)
4242
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -45,7 +45,7 @@ class UserApiAction @Inject constructor(
4545
TODO()
4646
}
4747

48-
@Post("/user/createWithArray")
48+
@Post("samplePrefix/user/createWithArray")
4949
@Description("Creates list of users with given input array")
5050
@RequestContentType(MediaTypes.APPLICATION_JSON)
5151
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -54,7 +54,7 @@ class UserApiAction @Inject constructor(
5454
TODO()
5555
}
5656

57-
@Post("/user/createWithList")
57+
@Post("samplePrefix/user/createWithList")
5858
@Description("Creates list of users with given input array")
5959
@RequestContentType(MediaTypes.APPLICATION_JSON)
6060
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -63,15 +63,15 @@ class UserApiAction @Inject constructor(
6363
TODO()
6464
}
6565

66-
@Delete("/user/{username}")
66+
@Delete("samplePrefix/user/{username}")
6767
@Description("Delete user")
6868
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
6969
fun deleteUser(
7070
@PathParam("username") username: kotlin.String) {
7171
TODO()
7272
}
7373

74-
@Get("/user/{username}")
74+
@Get("samplePrefix/user/{username}")
7575
@Description("Get user by user name")
7676
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
7777
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -80,7 +80,7 @@ class UserApiAction @Inject constructor(
8080
TODO()
8181
}
8282

83-
@Get("/user/login")
83+
@Get("samplePrefix/user/login")
8484
@Description("Logs user into the system")
8585
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
8686
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
@@ -90,14 +90,14 @@ class UserApiAction @Inject constructor(
9090
TODO()
9191
}
9292

93-
@Get("/user/logout")
93+
@Get("samplePrefix/user/logout")
9494
@Description("Logs out current logged in user session")
9595
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
9696
fun logoutUser() {
9797
TODO()
9898
}
9999

100-
@Put("/user/{username}")
100+
@Put("samplePrefix/user/{username}")
101101
@Description("Updated user")
102102
@RequestContentType(MediaTypes.APPLICATION_JSON)
103103
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)

0 commit comments

Comments
 (0)