← Back to Pull requests

[BUG][TYPESCRIPT] Fix string enum values containing "/*" being corrupted to "/_*" #25613

Closed
unknown closed this pull request without merging on Nov 11, 2026 12:52 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 18:02 UTC
Author

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 with escapeText(), which chains into escapeUnsafeCharacters():

public String escapeUnsafeCharacters(String input) {
    return input.replace("*/", "*_/").replace("/*", "/_*");
}

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 value foo/ 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() in AbstractTypeScriptClientCodegen (covering typescript-fetch, typescript-axios, typescript-angular, typescript-rxjs, typescript-node, typescript-nestjs, and the other generators extending it) and in the legacy TypeScriptClientCodegen (the typescript generator) now escapes the value with the new escapeTextForStringLiteral(): it applies the same string-literal escaping as escapeText() (backslashes, quotes, control characters) but leaves / and / untouched.

  • Everything else is unchanged: 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, across typescript (legacy TypeScriptClientCodegen.toEnumValue), typescript-fetch and typescript-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 — proving escapeUnsafeCharacters() still applies wherever text lands in comments.

  • Full org.openapitools.codegen.typescript test 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

  • 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
      

    (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.)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

  • (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() in AbstractTypeScriptClientCodegen and the legacy TypeScriptClientCodegen now uses the new escapeTextForStringLiteral(), which keeps all string-literal escaping but leaves comment delimiters untouched.

  • Comment escaping where text lands in block comments (e.g. model descriptions) is unchanged.

  • Adds regression and guard tests, plus a reproducer spec for #24572.
  • <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. -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: thekhegay Review duration: 1130m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%