← Back to Pull requests

fix(typescript-axios): preserve sibling properties in oneOf models #25636

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 12, 2026 09:37 UTC
Author

<details>
<summary>AI disclosure — Codex, GPT-6 Astra (High)</summary>

Codex investigated the generator, implemented the change and review follow-up, wrote the synthetic fixtures and regression tests, ran the local checks below, and drafted this PR. I supplied the problem, requested an upstream fix, and asked for alignment with the project's contribution requirements.

The work included distinguishing enclosing constraints from union-branch fields, checking generated SDK parameter and response types, and exercising request serialization and response handling. The checks also exposed the pre-existing discriminator/string-enum limitation documented below.

</details>

Description

Closes #25635.

When an object declares properties alongside oneOf, typescript-axios emits only the union and drops those properties. A response such as Receipt loses its required id; adding that field to the shared alternatives would incorrectly require it in request bodies.

This change intersects the union with the enclosing schema's properties:

export type Receipt = (LinkSubmission | TextSubmission) & {
    'id': string;
    'state': ReceiptStateEnum;
    'owner': Owner;
    'note'?: string | null;
};

Only enclosing properties enter the intersection. Plain unions and branch-only properties retain their existing behavior. Ordinary models and the intersection share property/enum rendering, and separate model files import referenced sibling types.

An enclosing required: [id] also constrains presence when it has no sibling properties. This produces (LinkSubmission | TextSubmission) & { 'id': unknown }: the field becomes required while each branch retains its own field type.

Import selection uses the complete imports list whenever the model has oneOf, including when hasAllOf is also set. A direct template regression verifies that both parent and branch imports appear exactly once. This is a defensive template fix, not new end-to-end support for mixed allOf/oneOf: current schema processing can discard that combination before rendering.

Validation

  • Full Maven reactor ./mvnw -B package -Dmaven.javadoc.skip=true succeeds with JDK 21: 5,886 tests, zero failures/errors, 18 skipped. All 20 Axios tests pass.

  • The fixture matrix covers combined/separate models and constant-object/string enums: required/optional/nullable fields, deprecation, sibling enum declarations, referenced imports, discriminator grouping, required-only constraints, and exclusion of branch-only fields.

  • Strict TypeScript 5.9.3 checks exercise SDK request/response types, missing fields, branch narrowing, and required-only intersections that still reject a wrong branch field type. Both layouts pass with default enums. With stringEnums=true, the non-discriminator contracts pass in both layouts.

  • Generated SDKs in all four layout/enum combinations pass Axios-adapter request serialization and response pass-through tests.

  • All 836 sample configurations regenerate successfully. The only sample changes against master remain the two Fruit declarations that now include their optional sibling color.

  • All generator documentation exports with no changes; git diff --check passes.
  • Existing limitation: with stringEnums=true, literal discriminator intersections can reduce an enum-based alternative to never. This reproduces with unmodified 7.27.0 and is excluded from the passing string-enum type-contract checks. Runtime checks compile the generated SDK itself in all four combinations.

    PR checklist

  • Read the contribution guidelines.

  • Run the full Maven reactor package build and tests listed above.

  • Regenerate all samples with ./bin/generate-samples.sh ./bin/configs/*.yaml and inspect the diff.

  • Export all generator documentation with ./bin/utils/export_docs_generators.sh.

  • Mention the TypeScript Axios technical committee member: @nicokoenig.
  • <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Fixes typescript-axios dropping properties declared alongside oneOf, so types like Receipt no longer lose their id, state, owner, and note fields. The generated union is now intersected with the enclosing schema's properties:

    export type Receipt = (LinkSubmission | TextSubmission) & {
        'id': string;
        'state': ReceiptStateEnum;
        'owner': Owner;
        'note'?: string | null;
    };
    

    Closes #25635.

    Details

  • Only properties declared on the enclosing schema are included, so plain oneOf unions like Submission stay unchanged.

  • An enclosing required list constrains presence even without sibling properties, producing (LinkSubmission | TextSubmission) & { 'id': unknown }.

  • Discriminator unions keep their mapping expression inside the intersection.

  • Models with oneOf now import their full imports list, so branch and sibling types appear exactly once, including when allOf is also present.

  • Regenerating all Axios samples changes only two Fruit declarations, which now include their previously omitted optional color property.
  • <sup>Written for commit dfd6fa63c7e139cd834cc837595e32adaf14a8ca. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/25636?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: 3063m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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.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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #25636"
    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: 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: 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: 27.7% · Safe to merge
    27.7%