OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] Missing enum values on generated model

Open
#21,138 1 comment 0 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

While generating java code from a yaml definition, the generated class remains empty on specific enum definition implying allOf and enum

openapi-generator version

7.12.0

OpenAPI declaration file content or url

The Yaml definition contains a StatusCode refering to a CoreStatusCode. This CoreStatusCode will be used in other schemas as a common enum list.

components:
  schemas:
    CoreStatusCode:
      type: string
      enum:
        - Cover
        - NoCover
        - Inactive
        - Rejected
        - Closed
    StatusCode:
      type: string
      allOf:
        - $ref: '#/components/schemas/CoreStatusCode'
        - type: string
          enum:
            - Partial
            - Pending
            - CheckPolicy

Full code https://gist.github.com/jswale/97939ceffa5a9bf066db5bf78a7da658

Steps to reproduce

Save the the yaml definition to /path/to/api.yaml and run the command line tool

openapi-generator generate -i /path/to/api.yaml -g java -o output

Open the file output/src/main/java/org/openapitools/client/model/StatusCode.java and see that the values are missing

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.12.0")
public class StatusCode {
  public StatusCode() {
  }
...

Remark
Using online tools such as https://editor.swagger.io/ is able to display correctly the expected values

StatusCode [string]
Enum: [ Cover, NoCover, Inactive, Rejected, Closed, Partial, Pending, CheckPolicy ]

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 YAML declaration and reproduce the issue using openapi-generator generate -i /path/to/api.yaml -g java -o output. Inspect output/src/main/java/org/openapitools/client/model/StatusCode.java and compare it with the expected combined enum values shown in the issue; done means the generated model contains all listed values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.