swagger-api / swagger-api/swagger-codegen

[JAVA] ISSUES GENERATING REUSABLE ENUM

Open
#9,267 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Hi,
If we use "reusable enum", the jaxrs-resteasy generated Server Stub produces a corrupted java enum.

Swagger-codegen version

we are using SwaggerHub with openApi 3.0.0 to design our RESTApi.

Swagger declaration file content or url

This is the yaml code definition of reusable Enum on Swagger

components:              
  schemas:
    SchedulerStatus:
      type: object
      properties:
        myEnum:
          $ref: '#/components/schemas/MyEnum'
          
    MyEnum:
      type: string
      enum:
        - "A"
        - "B"
        - "C"

And this is the generated Java Enum

public enum MyEnum {
    {values=[A, B, C], enumVars=[{name=A, value="A"}, {name=B, value="B"}, {name=C, value="C"}]}
}

This is the jaxrs-resteasy generated Server Stub project

jaxrs-resteasy-server-generated.zip

Command line used for generation

Using the Swagger Export Tool to generate the code of jaxrs-resteasy Server Stub

Steps to reproduce

. Add a reusable Enum definition to any yaml API definition
. Generate the jaxrs-resteasy server stub with the Swagger Export tool

Related issues

The issue https://github.com/swagger-api/swagger-codegen/issues/4160#issue-188059632 has my same problem, but related to JAXRS-CXF. The proposed solution doesn't work for my issue.

Suggest a fix

There is a little bug in the jaxrs-resteasy server stub codegen because, if I define the enum in the properties of an object, it's generated correctly.

Cheers, Alessandro

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 reproducing the issue with the provided reusable-enum YAML through the Swagger Export Tool and the jaxrs-resteasy server-stub generator. Compare the generated reusable MyEnum with the correctly generated inline-property enum; done means the reusable definition produces valid Java enum source with A, B, and C values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend
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.