Openapi-generator: [BUG] [Kotlin] Enums are generated with odd capitalization

Created on 29 Aug 2019  路  4Comments  路  Source: OpenAPITools/openapi-generator

Description

Kotlin generator generates Kotlin enums with strange capitalization: it lower-cases the first enum item letter (e.g. generates rED instead of RED).

openapi-generator version

Generator Version 4.1.1
Spec Version 3.0.2

OpenAPI declaration file content or url
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
Command line used for generation

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.

Steps to reproduce

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.

Related issues/PRs

Not found.

Suggest a fix

Generate Kotlin enums with the same capitalization as given in the declaration file (do not lower case the first letter).

Kotlin Bug

Most helpful comment

Set enumPropertyNaming to "UPPERCASE"
config.json:

{
     "enumPropertyNaming" : "UPPERCASE"
}

openapi-generator generate -i my-models.yml -g kotlin -c config.json

All 4 comments

馃憤 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):

https://kotlinlang.org/docs/reference/enum-classes.html

Was this page helpful?
0 / 5 - 0 ratings