From 015b4047290ab3dd43ad6b9d4d63e5689277d12a Mon Sep 17 00:00:00 2001 From: Yutaka Miyamae <48900426+yutaka0m@users.noreply.github.com> Date: Sun, 1 Mar 2020 18:58:58 +0900 Subject: [PATCH] [kotlin]Fix ktor doesn't generate nullable types (#5258) * If not required, need `? = null` * run ./bin/kotlin-server-petstore.sh * Added `?` when value is `required` and `isNullable` * Rerun ./bin/kotlin-server-petstore.sh. But No differences --- .../resources/kotlin-server/libraries/ktor/Paths.kt.mustache | 2 +- .../ktor/src/main/kotlin/org/openapitools/server/Paths.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 fbb0db506dc..07a3ffca9bd 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}}*/ @KtorExperimentalLocationsAPI - @Location("{{path}}") class {{operationId}}({{#allParams}}val {{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + @Location("{{path}}") class {{operationId}}({{#allParams}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{/bodyAllowed}} {{/operation}} 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 e6c59849df2..1983ab78a49 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 @@ -22,7 +22,7 @@ object Paths { * @param apiKey (optional) */ @KtorExperimentalLocationsAPI - @Location("/pet/{petId}") class deletePet(val petId: kotlin.Long, val apiKey: kotlin.String) + @Location("/pet/{petId}") class deletePet(val petId: kotlin.Long, val apiKey: kotlin.String? = null) /** * Finds Pets by status