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

Java enum classes generation is broken if errorOnUnknownEnum is turned on

Open
#1,093 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

Java enum classes generation is broken if java code is generated to use jackson library to serialize/deserialize json into java objects and errorOnUnknownEnum is turned on.

It affects at least 3.0.36 version.

The generated code looks like:

  @JsonCreator
  public static EnumName fromValue(String input) {
    ...
    throw new IllegalArgumentException("Unexpected value '" + text + "' for 'EnumName' enum.");
  }

the issue is that the method parameter has name input, while exception text uses variable with name text to produce error message.

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 locating the Java enum generation template or entry point that handles errorOnUnknownEnum, then compare the generated fromValue method with the reported snippet. Correct the inconsistent variable reference in the exception message and verify that generated Java enum code compiles and preserves the expected unknown-value behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.