Skip to content

fix(typescript): keep non-latin letters in enum keys - #25562

Open
thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-nonlatin-enum-keys
Open

thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-nonlatin-enum-keys

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

toEnumVarName in AbstractTypeScriptClientCodegen strips chars with ASCII \W, so enum values like À, Москва or 日本語 end up with empty key and generated code is { : 'À' }, which is TS1136 in every typescript-* generator with default settings
Now if nothing is left after sanitizeName, value is sanitized again with unicode (?U)\W, so Москва gives Москва: 'Москва'

I know allowUnicodeIdentifiers exists and gives valid output, but default output should not be invalid TypeScript. Only keys that are empty today change, anything that already produced non-empty key is untouchd (Café is still Caf, Москва 2 is still _2). Same idea as #24427, default sanitization fixed in this class without new option

Added test with À, Москва and Нур-Султан in TypeScriptAngularClientCodegenTest, it fails on master (expected [À] but found [])

Full ./mvnw clean package passes apart from Kotlin tests (embedded Kotlin compiler fails on my JDK 25). Regenerated all 93 bin/configs/typescript*.yaml, no sample changes. Did not run other configs, only typescript abstract class is touched. Generated typescript-angular and typescript-fetch for a spec with À and Москва enums pass tsc --strict, typescript-axios has no syntax errors (only missing axios module in my scratch dir)

This is typescript part of #16928, dart part is not touched

Fixes #9739

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.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim


Summary by cubic

Fixes toEnumVarName in AbstractTypeScriptClientCodegen so enum values containing only non-Latin characters no longer produce invalid TypeScript like { : 'Москва' }.

  • When ASCII sanitization strips everything, the value is re-sanitized with a Unicode-aware pattern, keeping letters such as À, Москва, or Нур-Султан.
  • Values that already produce a non-empty key are unchanged (Café still becomes Caf).
  • Adds tests for non-Latin enum values in TypeScriptAngularClientCodegenTest and fixes [BUG] [typescript-axios] utf8 values enum generated wrong  #9739.

Written for commit 9336037. 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.

No issues found across 2 files

View guided diff | Re-trigger cubic

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-axios] utf8 values enum generated wrong

1 participant