Bug Report Checklist
Description
When generating Kotlin multiplatform code, an enum defined in /components/schemas using x-enum-varnames generates an enum with toString() overridden to return its value, like in this abbreviated example:
@Serializable
enum class AllowFoo(val value: kotlin.String) {
@SerialName(value = "0")
DISALLOW("0"),
@SerialName(value = "1")
ALLOW("1");
override fun toString(): kotlin.String = value
}
But when an enum is declared inline, the generated class does not override toString() and it serializes to the constant's name in code. In the example spec (link below,) the X-Allow-Foo-Ref header declaration generates XAllowFooExampleGet, whose values serialize to "DISALLOW" and "ALLOW" respectively, instead of "0" and "1".
openapi-generator version
Discovered in 7.21.0, verified in master.
OpenAPI declaration file content or url
See https://gist.github.com/brandon-level/bbcf8d4a35beb1887b063ab815c91b02
Generation Details
java -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g kotlin -i x-enum-varnames-demo.yml -o ~/Desktop/openapi-demo-out -p library=multiplatform --additional-properties dateLibrary=kotlinx-datetime
Steps to reproduce
Generate classes from the schema, compare generated classes
Suggest a fix
Update code generation for inline enums using x-enum-varnames to override toString(), like for -level enum declarations.
Bug Report Checklist
No validation issues detected.Description
When generating Kotlin multiplatform code, an enum defined in /components/schemas using
x-enum-varnamesgenerates an enum withtoString()overridden to return its value, like in this abbreviated example:But when an enum is declared inline, the generated class does not override
toString()and it serializes to the constant's name in code. In the example spec (link below,) theX-Allow-Foo-Refheader declaration generatesXAllowFooExampleGet, whose values serialize to "DISALLOW" and "ALLOW" respectively, instead of "0" and "1".openapi-generator version
Discovered in 7.21.0, verified in master.
OpenAPI declaration file content or url
See https://gist.github.com/brandon-level/bbcf8d4a35beb1887b063ab815c91b02
Generation Details
java -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g kotlin -i x-enum-varnames-demo.yml -o ~/Desktop/openapi-demo-out -p library=multiplatform --additional-properties dateLibrary=kotlinx-datetimeSteps to reproduce
Generate classes from the schema, compare generated classes
Suggest a fix
Update code generation for inline enums using
x-enum-varnamesto overridetoString(), like for -level enum declarations.