Skip to content

Commit 558d123

Browse files
Mordagjimschubert
authored andcommitted
[Kotlin][Client] Enum toString handling (OpenAPITools#5327)
* Added toString to enum_class script This toString avoids using the enum var name and uses the enum's value instead. This will fix cases when enum var name and value are quite different. * Updated enum template Co-Authored-By: Jim Schubert <[email protected]> Co-authored-by: Jim Schubert <[email protected]>
1 parent e167787 commit 558d123

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ import kotlinx.serialization.internal.CommonEnumSerializer
4141

4242
{{/enumVars}}{{/allowableValues}}
4343

44+
/**
45+
This override toString avoids using the enum var name and uses the actual api value instead.
46+
In cases the var name and value are different, the client would send incorrect enums to the server.
47+
**/
48+
override fun toString(): String {
49+
return value{{^isString}}.toString(){{/isString}}
50+
}
51+
4452
{{#multiplatform}}
4553
{{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{classname}}>("{{classname}}", values(), values().map { it.value.toString() }.toTypedArray())
4654
{{/multiplatform}}

0 commit comments

Comments
 (0)