← Back to Pull requests

fix(typescript): do not import enum literals of anyOf params as models #25670

Open
unknown opened this pull request with 434 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 14, 2026 10:02 UTC
Author

Since SIMPLIFY_ONEOF_ANYOF_ENUM (on by default) turns anyOf of enum refs into one inline enum, param type becomes literal union like 'value1' | 'value2'. toModelImportMap splits it on | and every member passes needToImport, so api file gets import { 'value1' } from ... (fetch alos html-escapes it to 'value1'), integer enums give import { 1 } from '../models/1'. Generated client does not compile. Not an escaping issue, these imports should not be there at all

needToImport in AbstractTypeScriptClientCodegen now skips literal members (quote anywhere, or leading digit), they are never model names. Fixes typescript-fetch, typescript-angular, typescript-node and typescript, all of them go through this method

Added test in TypeScriptFetchClientCodegenTest with string and integer enums, it fails on master, other typescript tests pass. Regenerated all 93 typescript configs, no sample changes. For the issue spec generated fetch client passes tsc --strict, on master it gives 90 errors

Fixes #22682

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

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Fixes TypeScript code generators emitting broken model imports for inlined enum literal values. When anyOf combines enum schemas, SIMPLIFY_ONEOF_ANYOF_ENUM inlines them into literal unions, so the generated API file previously got import { 1 } from '../models/1' or an HTML-escaped 'value1' import, neither of which compiles. Fixes #22682.

    Bug Fixes

  • needToImport in AbstractTypeScriptClientCodegen now skips unions whose members are all literal values; a model next to a literal in a union is still imported.

  • Applies to typescript, typescript-angular, typescript-fetch, and typescript-node, which all share this code path.

  • Adds regression tests in TypeScriptFetchClientCodegenTest covering string and integer enums and the mixed literal-with-model union; generated samples for all 93 TypeScript configs are unchanged.
  • <sup>Written for commit 84530c67688f8527e785742dbdb61151209d9723. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/25670?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: 434 lines (+325 / -109) across 5 files Reviewer: thekhegay Review duration: 157m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 434 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.363
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #25670"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 24.1% · Safe to merge
    24.1%