Skip to content

[BUG] Java generators add underscore to enums #21059

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

Closed
5 of 6 tasks
joystuffs opened this issue Apr 8, 2025 · 2 comments
Closed
5 of 6 tasks

[BUG] Java generators add underscore to enums #21059

joystuffs opened this issue Apr 8, 2025 · 2 comments

Comments

@joystuffs
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

after updating to version 7.12.0 the current configuration produces enums with unexpected 'underscore'

 <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                            <generatorName>java</generatorName>
                            <skipValidateSpec>true</skipValidateSpec>
                            <strictSpec>true</strictSpec>
                            <generateApis>false</generateApis>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <generateModelTests>false</generateModelTests>
                            <apiPackage>com.api</apiPackage>
                            <modelPackage>com.api</modelPackage>
                            <typeMappings>
                                <typeMapping>Double=java.math.BigDecimal</typeMapping>
                                <typeMapping>Boolean=boolean</typeMapping>
                                <typeMapping>Date=String</typeMapping>
                                <typeMapping>UUID=String</typeMapping>
                            </typeMappings>
                            <importMappings>
                                <importMapping>Double=java.math.BigDecimal</importMapping>
                                <importMapping>Boolean=boolean</importMapping>
                                <importMapping>Date=String</importMapping>
                                <importMapping>UUID=String</importMapping>
                            </importMappings>
                            <configOptions>
                                <useJakartaEe>true</useJakartaEe>
                                <dateLibrary>custom</dateLibrary>
                                <library>resteasy</library>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <openApiNullable>false</openApiNullable>
                                <additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor</additionalModelTypeAnnotations>
                                <performBeanValidation>true</performBeanValidation>
                                <useBeanValidation>true</useBeanValidation>
                                <serializationLibrary>jackson</serializationLibrary>
                            </configOptions>
                        </configuration>

I tried to play around adding :

<enumPropertyNaming>original</enumPropertyNaming>

but the generator throws exception as the only types allowed are MACRO_CASE and legacy

even when I try to add :

removeEnumValuePrefix=true

or any similar/related enum config, nothing happens.

I looked into the source code but I couldn't fine a way to over come this problem and keep the previous behaviour.

probably there is something I miss with the configuration and that leads to this enum generation issue.

below the generated enum after the update

C2_C("C2C"),
 
 CORE("CORE");

before the update with version 7.5.0

B2B("C2C"),
 
 CORE("CORE");
openapi-generator version

7.12.0

OpenAPI declaration file content or url

below the example of the openapi definition

"Type": {
        "type": "string",
        "description": "Type [C2C, CORE]",
        "enum": [
          "C2C",
          "CORE"
        ]
      }
Generation Details

we use the openapi-generator-maven-plugin

version : 7.12.0

Steps to reproduce

just run the maven command with the two versions and you will be able to replicate the issue

Related issues/PRs
Suggest a fix
@wing328
Copy link
Member

wing328 commented Apr 10, 2025

did you try setting the option enumPropertyNaming to legacy?

ref: https://openapi-generator.tech/docs/generators/java/

@joystuffs
Copy link
Author

thank you for the reference. that solved the issue.

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

No branches or pull requests

2 participants