Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA] Enum generation fails on same values in upperCase and lowerCase #12624

Closed
4 of 6 tasks
mbreevoort opened this issue Jun 17, 2022 · 6 comments · Fixed by #17018
Closed
4 of 6 tasks

[BUG][JAVA] Enum generation fails on same values in upperCase and lowerCase #12624

mbreevoort opened this issue Jun 17, 2022 · 6 comments · Fixed by #17018

Comments

@mbreevoort
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

For Java the enum's are generated with name upper and value is the value of the openapi spec.
In our case we need to be compliant with another specification which has the same value in uppercase and lowercase.
This causes a compile error in the java generated enum:

MyObject.java:90: error: variable S is already defined in enum UnitEnum
    S("S"),
    ^
1 error

Is there a config setting for this? (Could not find it)

Actual:
Compile exception (see above)

Expected:
Generation of multiple casing should compile the java enum file
Maybe just like org.jsonschema2pojo.Jsonschema2Pojo It generates a enum name with an underscore S_("S"), for the second name.

openapi-generator version

'org.openapi.generator' version '5.4.0'

OpenAPI declaration file content or url
    MyObject:
      type: object
      properties:
        description:
          type: string
        unit:
          type: string
          enum:
          - s
          - S
Generation Details

gradle plugin is used

Steps to reproduce

Generate the models

Related issues/PRs

In this issue a same problem is described but not solved: #12187 (comment)

Suggest a fix

Maybe just like org.jsonschema2pojo.Jsonschema2Pojo It generates a enum name with an underscore S_("S"), for the second name.

@dmmarques
Copy link

I am currently facing the same issue, have you had any updates on this ?

@mbreevoort
Copy link
Author

No updates.
I don't know if it helps to create a pull request for this when no maintainer responds...

@wing328
Copy link
Member

wing328 commented Nov 4, 2023

Just responded to a similar PR/issue but for C#: #16981 (comment)

If we add the enumNameMapping option, it should fix the issue, right?

@dmmarques
Copy link

Does it add a suffix when both generated values are the same ?

@wing328
Copy link
Member

wing328 commented Nov 4, 2023

It doesn't. Using the example provide in the issue. the command line input would look like

--enumNameMapping s=LOWER_CASE_S,S=UPPER_CASE_S

so that users will have complete control of the enum naming to handle edge cases reported in this issue.

@wing328
Copy link
Member

wing328 commented Nov 13, 2023

Merged #17018 to fix the issue

Please pull the latest master to give it a try. e.g.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml  -o /tmp/java/ --enum-name-mappings sold=UNAVAILABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants