swagger-api / swagger-api/swagger-codegen

[Kotlin] Invalid enum var names

Open
#8,116 0 comments 0 reactions 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

When enums name start with a number, the generated code won't compile

Swagger-codegen version

2.4.0-SNAPSHOT

Swagger declaration file content or url
"enum":[
    "1name"
]
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i swagger.json -c config.json -l kotlin -o tmp

Steps to reproduce

Add an enum parameter to swagger file; generate and compile.

Related issues/PRs
Suggest a fix/enhancement

The enumeration name can be prefixed by an underscore, it's done like this for the model name.

Another solution is to surround illegals names with backticks, but enum may be tricky to use (Status.1available). And what I understand of kotlin coding convention is backticks are acceptable only for names in tests.

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 by reproducing the issue with swagger-codegen-cli.jar, the supplied swagger.json enum value, and the Kotlin generator. Inspect the Kotlin generation templates or entry points responsible for enum names. Done means the generated Kotlin code compiles when an enum value begins with a number, while preserving valid names for other 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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.