swagger-api / swagger-api/swagger-codegen-generators

bug in java code generation for Enumeration in swagger document

Open
#1,176 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

For java code generation from swagger, for enums, there is a bug in code generation.
I have tried many versions so far but no luck. To replicate the issue, please take the latest stable version or this:

<swagger.codegen.version>3.0.45</swagger.codegen.version>
I have already added under properties:
<errorOnUnknownEnum>true</errorOnUnknownEnum>

The code generated has:

"Unexpected value '" + text + "' for 'MyTest' enum."
instead of:
"Unexpected value '" + input+ "' for 'MyTest' enum."

@JsonCreator
    public static TypeEnum fromValue(String input) {
      for (TypeEnum b : TypeEnum.values()) {
        if (b.value.equals(input)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + text + "' for 'MyTest' enum.");
    }

Also there is mention of this change here:
https://github.com/swagger-api/swagger-codegen-generators/pull/713

May be the same is missing in the latest version 3.x.x

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

Search the Java enum generation template for fromValue(String input), then compare it with the change described in swagger-codegen-generators PR #713. Reproduce the generated output using swagger.codegen.version 3.0.45 and verify that the enum error message uses the method's input value.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.