Skip to content

Commit 75b04bb

Browse files
authored
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.
1 parent 6a8039c commit 75b04bb

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

  • modules/openapi-generator/src/main/resources/kotlin-client
  • samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models

modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import kotlinx.serialization.*
7474
* This solves a problem when the variable name and its value are different, and ensures that
7575
* the client sends the correct enum values to the server always.
7676
*/
77-
override fun toString(): String = value{{^isString}}.toString(){{/isString}}
77+
override fun toString(): kotlin.String = value{{^isString}}.toString(){{/isString}}
7878

7979
companion object {
8080
/**

samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class PetEnum(val value: kotlin.String) {
4848
* This solves a problem when the variable name and its value are different, and ensures that
4949
* the client sends the correct enum values to the server always.
5050
*/
51-
override fun toString(): String = value
51+
override fun toString(): kotlin.String = value
5252

5353
companion object {
5454
/**

0 commit comments

Comments
 (0)