OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Kotlin] Enums are generated with odd capitalization

Open
#3,804 13 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Kotlin Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided OpenAPI declaration using openapi-generator generate -i my-models.yml -g kotlin, then inspect the generated StatusColorEnum.kt. Check the Kotlin generator output path and confirm the Gradle plugin produces the same result. Done means enum constant identifiers preserve the declaration's capitalization while serialized names remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.