OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Generator incorrectly altering enum values
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
There are 2 places where i observed this bug. One of which was with an array of camelCase values being changed to snake_case and the other with an enum value that contains a number.
S4A -> S4_A but expected S4A
or
middleAgeFemale -> MIDDLE_AGE_FEMALE but expected MIDDLEAGEFEMALE
openapi-generator version
version >7.4.0. This issue does not occur in 7.4.0
OpenAPI declaration file content or url
Schema1
type: string
enum:
- S4A
- ENUM_VALUE_ONE
- ENUM_VALUE_TWO
- ENUM_VALUE_THREE
This produces enum values S4_A, ENUM_VALUE_ONE, ENUM_VALUE_TWO, ENUM_VALUE_THREE
or
Schema1:
type: string
example: "middleAgeFemale"
enum:
- "middleAgeFemale"
- "middleAgeMale"
- "seniorFemale"
- "seniorMale"
- "teenageBoy"
- "teenageGirl"
- "youngAdultFemale"
- "youngAdultMale"
This produces enum values MIDDLE_AGE_FEMALE, MIDDLE_AGE_MALE ...
Generation Details
Java OpenAPI Generator in Spring Boot application
Steps to reproduce
- Create a schema with an enum value of type string.
- Include a number in one of the enum values or create camelCase values only
- run the code generator
- results for the number will look like this:
S4A -> S4_A but expected S4A
or
middleAgeFemale -> MIDDLE_AGE_FEMALE but expected MIDDLEAGEFEMALE
Related issues/PRs
Suggest a fix
My work around for this was to use x-enum-varnames to manually fix these 2 cases
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the Java OpenAPI Generator against the two schemas in the report and compare the generated enum identifiers with the declared values. Trace the generator entry point that converts string enum values, then verify that S4A and camelCase values remain unchanged while already-uppercase underscore values are preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100