swagger-api / swagger-api/swagger-codegen

Enum values OFF and ON not getting generated properly.

Open
#2,559 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature Feature: Enum help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I observed this weird issue today when generating java client using maven codegen plugin, that enum values like OFF and ON are somehow ignored. Lets say in my YAML definition, there is:

laziness:
        description: Flag to denote whether laziness should be enabled or disabled.
        type: string
        enum: [ ON, OFF ]

In the above scenario, no enum type is generated, and the class member laziness have the type String.
But, If the definition was as follows:

laziness:
        description: Flag to denote whether laziness should be enabled or disabled.
        type: string
        enum: [ ON, OFF, MEH ]

Codegen generates the enum with just one value - MEH, and the class member is assigned the enum type.

But if I put quotes around them, like:

laziness:
        description: Flag to denote whether laziness should be enabled or disabled.
        type: string
        enum: [ "ON", "OFF", "MEH" ]

All values are included in the generated enum.

I use the latest version of swagger-codegen-maven-plugin, version 2.1.6

PS: It works perfectly when generating from editor.swagger.io

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 swagger-codegen Maven plugin using the YAML enum examples, then inspect how enum values are parsed before Java client generation. Done means unquoted ON and OFF values generate the same enum as quoted values, while the existing MEH case remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, yaml
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.