[BUG][TYPESCRIPT] Fix string enum values containing "/*" being corrupted to "/_*" #25613
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #25613"
general
weight: 0.35
thekhegay
Description
Fixes #24572.
In the TypeScript family, string enum values are emitted inside quoted string literals (e.g.
AB: 'a/b'), but they were escaped withescapeText(), which chains intoescapeUnsafeCharacters():That rewriting exists so that text interpolated into
/ /block comments cannot terminate the comment early. Enum values, however, only ever appear inside string literals where those sequences are harmless — so the escaping silently corrupts legitimate user data: an enum valuefoo/was generated as'foo/_', and the generated constant no longer matches the value the server actually sends (e.g. wildcard patterns).What this PR changes (narrow fix)
toEnumValue()inAbstractTypeScriptClientCodegen(coveringtypescript-fetch,typescript-axios,typescript-angular,typescript-rxjs,typescript-node,typescript-nestjs, and the other generators extending it) and in the legacyTypeScriptClientCodegen(thetypescriptgenerator) now escapes the value with the newescapeTextForStringLiteral(): it applies the same string-literal escaping asescapeText()(backslashes, quotes, control characters) but leaves/and/untouched.escapeText()/escapeUnsafeCharacters()still apply wherever text is rendered inside comments — e.g. a model description containing/is still generated as_\/inside the block comment.This is deliberately not the sweeping "escaping should be context-dependent" redesign explored in the older, still-open PR #19528 / #19553 / #19554: those restructure the whole escaping pipeline and change behavior for every interpolated text. This PR keeps the change scoped to the enum-value call sites only, so comment-safety guarantees elsewhere remain exactly as they are today, and the diff stays reviewable. (The underlying design issue of context-blind escaping is tracked in #23962.)
Tests
SharedTypeScriptTest.enumValueWithCommentDelimitersIsNotCorruptedTest— a model with enum values["a/b", "/c", "plain"]must generate the values'a/b','/c','plain'unchanged, acrosstypescript(legacyTypeScriptClientCodegen.toEnumValue),typescript-fetchandtypescript-axios(AbstractTypeScriptClientCodegen.toEnumValue), and the corrupted forms ('/_','_/') must not appear.SharedTypeScriptTest.commentDelimiterEscapingIsStillAppliedToCommentsTest— comment-injection guard: for the same model, the description containing/is still escaped to_\/inside the generated block comment (typescript-axios), while the enum values in the same file stay intact — provingescapeUnsafeCharacters()still applies wherever text lands in comments.org.openapitools.codegen.typescripttest package: 235 tests, 0 failures, 0 errors.Samples
Regenerated the petstore samples for the affected generators via
./bin/generate-samples.sh bin/configs/typescript-axios-default.yaml bin/configs/typescript-fetch-default.yaml bin/configs/typescript-fetch-default-v3.0.yaml bin/configs/typescript-axios-with-string-enums.yaml bin/configs/typescript-fetch-with-string-enums.yaml: the diff is empty (no petstore enum value contains comment delimiters, and values without them generate byte-identical output).PR checklist
(For Windows users, please run the script in WSL)
Commit all changed files.
This is important, as CI jobs will verify _all_ generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
(Done via Maven in a Docker container; the affected TypeScript petstore samples above were regenerated and the resulting diff is empty, so no sample changes are committed. Docs generators are not affected by this change.)
(Left to the maintainers to route to the TypeScript technical committee members, to avoid direct @ mentions.)
<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Fixes #24572: TypeScript string enum values containing
/or/were silently rewritten to/_and*_/, corrupting legitimate values like wildcard patterns when comment-escaping meant for block comments was applied to string literals.toEnumValue()inAbstractTypeScriptClientCodegenand the legacyTypeScriptClientCodegennow uses the newescapeTextForStringLiteral(), which keeps all string-literal escaping but leaves comment delimiters untouched.<sup>Written for commit f1084d7ace4a171245f77c925b0541b1abdc263a. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/25613?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->