diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 454ac58a6c52..6157644fe577 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -382,6 +382,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List ops = operations.getOperation(); ops.forEach(operation -> { + if (isKtor()) { + ArrayList params = new ArrayList<>(); + params.addAll(operation.pathParams); + params.addAll(operation.queryParams); + operation.vendorExtensions.put("ktor-params", params); + } + List responses = operation.responses; if (responses != null) { responses.forEach(resp -> { diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache index 48c8a7e49d88..37369e01463b 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache @@ -18,7 +18,7 @@ object Paths { {{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}}*/ {{#hasParams}} - @Resource("{{{path}}}") class {{operationId}}({{#pathParams}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/pathParams}}) + @Resource("{{{path}}}") class {{operationId}}({{#vendorExtensions.ktor-params}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/vendorExtensions.ktor-params}}) {{/hasParams}} {{^hasParams}} @Resource("{{{path}}}") class {{operationId}} diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt index 96b4afcaa488..c9a28c0ace5e 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt @@ -36,14 +36,14 @@ object Paths { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - @Resource("/pet/findByStatus") class findPetsByStatus() + @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.MutableList) /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - @Resource("/pet/findByTags") class findPetsByTags() + @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.MutableList) /** * Find pet by ID @@ -145,7 +145,7 @@ object Paths { * @param username The user name for login * @param password The password for login in clear text */ - @Resource("/user/login") class loginUser() + @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) /** * Logs out current logged in user session diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt index 96b4afcaa488..0dc3888eb309 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt @@ -36,14 +36,14 @@ object Paths { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - @Resource("/pet/findByStatus") class findPetsByStatus() + @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.List) /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - @Resource("/pet/findByTags") class findPetsByTags() + @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.List) /** * Find pet by ID @@ -145,7 +145,7 @@ object Paths { * @param username The user name for login * @param password The password for login in clear text */ - @Resource("/user/login") class loginUser() + @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) /** * Logs out current logged in user session