swagger-api / swagger-api/swagger-codegen

[Kotlin] Missing underscore prefix for numbers in enum

Open
#9,264 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Kotlin enum class generation is broken for wrong enum convention naming beginning with number.

Swagger-codegen version

2.4.2

Swagger declaration file content or url
"swagger": "2.0"
  TimeFormat:
    type: string
    enum:
      - 12h
      - 24h
Generates this corrupt kotlin file
import com.squareup.moshi.Json

/**
* 
* Values: 12h,24h
*/
enum class TimeFormat(val value: kotlin.String){

    @Json(name = "12h") 12h("12h"),

    @Json(name = "24h") 24h("24h");

}
Swift4 same file correct generation
import Foundation


public enum TimeFormat: String, Codable {
    case _12h = "12h"
    case _24h = "24h"

}
Command line used for Kotlin generation

swagger-codegen generate -l kotlin -i swagger.api.yaml -c swagger-codegen.config.json -o my_directory

Command line used for Swift4 generation

swagger-codegen generate -l swift4 -i swagger.api.yaml -c swagger-codegen.config.json -o my_directory

Suggest a fix/enhancement

Add test for naming conventions. Make strict name conventions rules for enum in .yaml file or for validator. Simple add of underscore is enough.

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

Start with the Kotlin generator invoked by swagger-codegen generate -l kotlin and trace how enum values from swagger.api.yaml become Kotlin enum members. Add a regression test for numeric enum values such as 12h and 24h, then verify generation produces valid Kotlin identifiers while preserving the original serialized values.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.