5

How to skip removing the common prefix from modelsEnum name? I have got an enum with single value (in the future I will have more values) and swagger code gen plugin generates the class with enum CODE instead of AIRPORT_CODE

properties:
  type:
    enum: ["AIRPORT_CODE"]
    description: the type of location that is identified by the value
gauee
  • 305
  • 3
  • 13
  • Your problem is right here https://github.com/swagger-api/swagger-codegen/blob/0ce6c7e3a8ad93c8c8a49b41b75a7f31561d75ce/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L3443 and it doesn't seem to be a way to change this behavior without modifying that method (or overriding it in the class corresponding to the language you want). You might want to choose a format for your enums that isn't catch by the `findCommonPrefixOfVars` method (if you can). – moondaisy Apr 20 '17 at 20:11

2 Answers2

2

There's a pull request that adds the --use-enum-common-prefix argument to address this issue, but it's not merged into master yet (as of time of writing). You can follow issue #4261 for updates.

For now you can try rebuilding swagger-codegen yourself with this PR included, and use your custom build to generate the code.

Helen
  • 87,344
  • 17
  • 243
  • 314
0

You just need to overwrite the default configuration with: removeEnumValuePrefix=false

Examples:

Maven:

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

Gradle:

openApiGenerate {
   ...
   additionalProperties = [
      removeEnumValuePrefix: "false"
   ]
}

For more details you can also take a look here: https://github.com/OpenAPITools/openapi-generator/pull/5166

r_benedikt
  • 34
  • 6