Skip to content

fix(core): keep enum var names unique after renaming duplicates - #25560

Open
thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/enum-dup-names-22074
Open

thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/enum-dup-names-22074

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

postProcessEnumVars renames duplicate enum names by appending a counter, but new name can already be taken by another entry. Etc/GMT-1 becomes EtcGmt12 and Etc/GMT+12 already has that name after sanitizing, so full timezone enum gives TS1117 in typescript-* and duplicate constant ETC_GMT_122 in java

Now dedupe repeats while names are still not unqiue. Second pass runs only when duplicates are left, so output that was valid before is not changed

Added unit test in DefaultCodegenTest with names of Etc/GMT+12, Etc/GMT+1, Etc/GMT0, Etc/GMT-1 and Etc/GMT-12, it fails on master and passes with the fix. Generated typescript-angular and java enums from the full timezone list in #17277 have no duplicate names

Ran all configs with ./bin/generate-samples.sh ./bin/configs/*.yaml, no sample changes. ./mvnw clean package passes except Kotlin generator tests, those fail on JDK 25 on my machine (embedded Kotlin compiler)

On earlier attempt #22087 answer was enumPropertyNamingReplaceSpecialChar. That option is typescript only, so java and every other generator has no workaround except enumNameMappings or x-enum-varnames. This change doesn't rename anything that was valid, so it is not breaking and needs no option

Fixes #22074
Fixes #17277

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Commit all changed files.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes enum variable name deduplication so renamed entries can no longer collide with existing names. postProcessEnumVars previously appended a counter on collision, but the new name could already be taken — e.g., Etc/GMT-1 becomes EtcGmt12, which collides with the sanitized name of Etc/GMT+12 — causing TS1117 errors in TypeScript generators and duplicate constants in Java. The pass now repeats until names are unique. Output that was already valid is unchanged, so this isn't breaking and needs no new option. Fixes #22074 and #17277.

Written for commit 991fa3b. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 5, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @OpenAPITools/generator-core-team

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][TYPESCRIPT] Duplicate enum keys cause TS1117 error [BUG] enum values can produce duplicates on generation

2 participants