OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generated enum constants have triple underscore when original contains ' - '
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?
- 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?
Description
After this fix: https://github.com/OpenAPITools/openapi-generator/pull/21459, when the original string contains a hyphen, surrounded by spaces, the generated enum constant now has three underscores:
"This - string" becomes "THIS___STRING"
Suggested fix: In this file:
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
Replace
modified = value.replaceAll("-", "_");
with:
modified = value.replaceAll(" - ", "_");
modified = value.replaceAll("-", "_");
It could also be that it needs to be fixed on a more fundamental level, because otherwise, there will probably be other edge cases as well.
openapi-generator version
7.15.0
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
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java and inspect the enum-constant transformation affected by PR 21459. Reproduce the "This - string" case, correct the generated name without introducing extra underscores, and verify the resulting generated output against the reported expectation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100