Skip to content

Commit 7198f71

Browse files
committed
[Kotlin Server] Use query parameters
1 parent c345e6a commit 7198f71

File tree

4 files changed

+14
-7
lines changed
  • modules/openapi-generator/src/main
  • samples/server/petstore
    • kotlin-server/ktor/src/main/kotlin/org/openapitools/server
    • kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server

4 files changed

+14
-7
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
382382
if (operations != null && !Objects.equals(library, Constants.JAXRS_SPEC)) {
383383
List<CodegenOperation> ops = operations.getOperation();
384384
ops.forEach(operation -> {
385+
if (isKtor()) {
386+
ArrayList<CodegenParameter> params = new ArrayList<>();
387+
params.addAll(operation.pathParams);
388+
params.addAll(operation.queryParams);
389+
operation.vendorExtensions.put("ktor-params", params);
390+
}
391+
385392
List<CodegenResponse> responses = operation.responses;
386393
if (responses != null) {
387394
responses.forEach(resp -> {

modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Paths {
1818
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
1919
{{/allParams}}*/
2020
{{#hasParams}}
21-
@Resource("{{{path}}}") class {{operationId}}({{#pathParams}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/pathParams}})
21+
@Resource("{{{path}}}") class {{operationId}}({{#vendorExtensions.ktor-params}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/vendorExtensions.ktor-params}})
2222
{{/hasParams}}
2323
{{^hasParams}}
2424
@Resource("{{{path}}}") class {{operationId}}

samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ object Paths {
3636
* Multiple status values can be provided with comma separated strings
3737
* @param status Status values that need to be considered for filter
3838
*/
39-
@Resource("/pet/findByStatus") class findPetsByStatus()
39+
@Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.MutableList<kotlin.String>)
4040

4141
/**
4242
* Finds Pets by tags
4343
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
4444
* @param tags Tags to filter by
4545
*/
46-
@Resource("/pet/findByTags") class findPetsByTags()
46+
@Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.MutableList<kotlin.String>)
4747

4848
/**
4949
* Find pet by ID
@@ -145,7 +145,7 @@ object Paths {
145145
* @param username The user name for login
146146
* @param password The password for login in clear text
147147
*/
148-
@Resource("/user/login") class loginUser()
148+
@Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String)
149149

150150
/**
151151
* Logs out current logged in user session

samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ object Paths {
3636
* Multiple status values can be provided with comma separated strings
3737
* @param status Status values that need to be considered for filter
3838
*/
39-
@Resource("/pet/findByStatus") class findPetsByStatus()
39+
@Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.List<kotlin.String>)
4040

4141
/**
4242
* Finds Pets by tags
4343
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
4444
* @param tags Tags to filter by
4545
*/
46-
@Resource("/pet/findByTags") class findPetsByTags()
46+
@Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.List<kotlin.String>)
4747

4848
/**
4949
* Find pet by ID
@@ -145,7 +145,7 @@ object Paths {
145145
* @param username The user name for login
146146
* @param password The password for login in clear text
147147
*/
148-
@Resource("/user/login") class loginUser()
148+
@Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String)
149149

150150
/**
151151
* Logs out current logged in user session

0 commit comments

Comments
 (0)