OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.99k stars 6.6k forks source link

[BUG] Incorrect ENUM generation #19066

Open Noed opened 4 months ago

Noed commented 4 months ago

Bug Report Checklist

Description

ENUM is being generated with additional "_" character when there's a number on the ENUM name.

openapi-generator version

Issue started on 7.7.0, works fine on 7.7.6.

OpenAPI declaration file content or url

Example ENUM attribute in the YAML spec:

        myAttribute:
          description: this is a ENUM            
          type: string
          enum:
          - MOVE2STOCK
          - MOVE2SHELF
          - KEEP
Generation Details

Java 17, Gradle build.

Steps to reproduce

Add ENUM attribute to the spec that has numbers in the attribute name. Generate java model using openapi generator 7.7.0. Look into the source code generated, the ENUM attribute names will have an "_" after the number.

For example:

  public enum MyAttributeEnum {
    MOVE2_STOCK("MOVE2STOCK"),
    MOVE2_SHELF("MOVE2SHELF"),
    KEEP("KEEP"),
Related issues/PRs
Suggest a fix
Trebuac commented 4 months ago

Hello, I got the same issue (different behaviour in my Java Enum generation between 7.6.0 and 7.7.0).

I suspect this commit to be the root cause : https://github.com/OpenAPITools/openapi-generator/commit/bfa26ea6be6af4984f94b60c67bc4fb0a5d76181#diff-a98cba8ecadaf5a662edc508aa5857972339552ec6bd6e4216680c7c6070e643

which is linked to this request https://github.com/OpenAPITools/openapi-generator/issues/4837

Sadly it seems that we can't change this behavior (some generator have the option to choose the 'enumPropertyNaming' - 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'), a feature request has been opened for Java/Spring : https://github.com/OpenAPITools/openapi-generator/issues/18987

wing328 commented 4 months ago

please refer to https://github.com/OpenAPITools/openapi-generator/pull/18594#issuecomment-2121945653 on how to fallback

Maran23 commented 4 months ago

Is there an option to just use the enum as is? Without any futher modifications?

AndresBena19 commented 2 months ago

Any idea when https://github.com/OpenAPITools/openapi-generator/pull/19277 will be merged?

magiusdarrigo commented 2 months ago

@AndresBena19 +1000