OpenAPITools / OpenAPITools/openapi-generator

[BUG] Missing value/name mapping for shared enum definition

Open
#11,266 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

If a type is defined as a shared enum in the open api specification and the values are not upper case only, the generated code will not deserialize/serialize the enum value properly.
If the type is defined as an inline enum type, the generated code is correct and serialization/deserialization works.

openapi-generator version

5.3.0, jaxrs-resteasy

OpenAPI declaration file content or url

Example snippet from .yaml definition:

...
TermOfPaymentEnum:
          type: string
          enum:
            - zero
            - ten
            - fifteen
...
Steps to reproduce
  1. Define a enum type with lower case values in components/schemas
  2. Generate the code with jaxrs-resteasy generator

The generated code is:

public enum TermOfPaymentEnum {
    ZERO, TEN, FIFTEEN
}

Notice that the generated enum has no value attribute and no fromValue and toString() implementations.
I would expect the following code:

public enum TermOfPaymentEnum {
  ZERO("zero"),

  TEN("ten"),

  FIFTEEN("fifteen"),


  private String value;

  TermOfPaymentEnum(final String value) {
    this.value = value;
  }

  @Override
  @JsonValue
  public String toString() {
    return String.valueOf(value);
  }
}
Related issues/PRs

REQ 8084

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 with the jaxrs-resteasy generator and compare generated code for the shared enum and inline enum cases described in the issue. Verify that lower-case OpenAPI values are preserved during serialization and deserialization, then add or run a regression test covering TermOfPaymentEnum-like values and confirm the generated enum includes the expected mapping behavior.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.