From 75b04bb96598f4b4faeb116d487f4b10cbaced87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roaldseth?= Date: Wed, 9 Aug 2023 09:09:21 +0200 Subject: [PATCH] Ensure enum classes toString() returns kotlin.String (#16247) When creating an enum where a valid value is `String`, the override of toString() will be the wrong type. Simply using `*kotlin*.String` will allow using `String` as a value in an enum. --- .../src/main/resources/kotlin-client/enum_class.mustache | 2 +- .../src/main/kotlin/org/openapitools/client/models/PetEnum.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache index 3a45715a03c..7d3793d57e5 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache @@ -74,7 +74,7 @@ import kotlinx.serialization.* * This solves a problem when the variable name and its value are different, and ensures that * the client sends the correct enum values to the server always. */ - override fun toString(): String = value{{^isString}}.toString(){{/isString}} + override fun toString(): kotlin.String = value{{^isString}}.toString(){{/isString}} companion object { /** diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt index f25afb05bf2..882b8ff106b 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt @@ -48,7 +48,7 @@ enum class PetEnum(val value: kotlin.String) { * This solves a problem when the variable name and its value are different, and ensures that * the client sends the correct enum values to the server always. */ - override fun toString(): String = value + override fun toString(): kotlin.String = value companion object { /**