Kotlin generator generates Kotlin enums with strange capitalization: it lower-cases the first enum item letter (e.g. generates rED instead of RED).
Generator Version 4.1.1
Spec Version 3.0.2
openapi: "3.0.2"
info:
version: "1.0.0"
title: Testing Kotlin generation
# We only care about schemas, but this prevents codegen error: "attribute paths is missing"
paths:
/dummy:
get:
responses:
'200':
description: OK
components:
schemas:
StatusColorEnum:
description: >
RGB.
type: string
enum:
- RED
- YELLOW
- GREEN
openapi-generator generate -i my-models.yml -g kotlin
NOTE: we actually use the Gradle plugin for code generation (org.openapi.generator version 4.1.1), but the above command-line tool gives the same result. However, we would like the fix to propagate to the Gradle plugin as well, so we can use in our build.
Run the command above and inspect the generated StatusColorEnum.kt. It will look like below:
package org.openapitools.client.models
import com.squareup.moshi.Json
/**
* RGB.
* Values: rED,yELLOW,gREEN
*/
enum class StatusColorEnum(val value: kotlin.String){
@Json(name = "RED")
rED("RED"),
@Json(name = "YELLOW")
yELLOW("YELLOW"),
@Json(name = "GREEN")
gREEN("GREEN");
}
Note the capitalization is very odd: instead of rED it should really be just RED.
Not found.
Generate Kotlin enums with the same capitalization as given in the declaration file (do not lower case the first letter).
馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
Set enumPropertyNaming to "UPPERCASE"
config.json:
{
"enumPropertyNaming" : "UPPERCASE"
}
openapi-generator generate -i my-models.yml -g kotlin -c config.json
Thanks. But, shouldn't the code generator generate enums with the capitalization given in the declaration file?
It seems odd that the default behavior would be to generate enums with capitalization like dOG and cAT. All caps with underscores seems to be the convention for Kotlin (as with Java):
Most helpful comment
Set enumPropertyNaming to "UPPERCASE"
config.json:
openapi-generator generate -i my-models.yml -g kotlin -c config.json