swagger-api / swagger-api/swagger-codegen
[Kotlin] Missing underscore prefix for numbers in enum
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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