Search code examples
javaenumsopenapiopenapi-generator

openapi-generator cuts beginning of enum names in generated class


Openapi-generator cuts beginning of enum names starting with "SB_". I don't understand why this happens or how to fix this.

This is a part of my openapi.yaml:

...
sb:
  type: string
  enum:
    - SB_150_150
    - SB_300_150
...

This is the generated class:

  public enum SbEnum {
    ...
    _150_150("SB_150_150")
    _300_150("SB_300_150")
    ...
  }

When I delete the first underscore from the first enum name the rest of enum names is generated correctly.

How can I achieve a result like this?

  public enum SbEnum {
    ...
    SB_150_150("SB_150_150")
    SB_300_150("SB_300_150")
    ...
  }

Solution

  • I tried to replicate your issue as I was working with openapi-generator at the moment, and I encountered the same issue. What resolved it for me was including extra option in the plugin configuration block in my pom.xml as follows

    <configuration>
            <additionalProperties>removeEnumValuePrefix=false</additionalProperties>
    </configuration>
    

    Hope that helps in your case as well, hopefully you don't need those prefixes actually removed somewhere else.

    I am using version 6.4.0 of the openapi-generator-maven-plugin