← Back to Pull requests

fix(typescript-axios): preserve primitive anyOf types and nullability #25638

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

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

Codex investigated the normalizer and Axios generator, implemented this 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 a separate upstream fix, and asked for alignment with the project's contribution requirements.

The work included examining cases beyond the original tests, reproducing a Fetch serialization regression from shared normalization changes, narrowing the production changes to Axios, and checking generated SDK types and runtime behavior. The broader fixtures also expose existing Fetch/Python failures, documented below.

</details>

Description

Closes #25637. This branch starts from master and is independent of #25636.

For a schema such as:

Hostname:
  type: string
  anyOf:
    - pattern: '^[a-z]+[.]example$'
    - pattern: '^[*][.][a-z]+[.]example$'

typescript-axios generates an empty interface and makes references nullable. SDK methods consequently accept numbers/null, and a returned hostname cannot be used as a string.

This change emits export type Hostname = string and preserves the enclosing primitive type on properties and method signatures. Explicitly nullable schemas emit string | null when their composition also permits null. Numeric predicates retain the enclosing numeric type. Existing model names are retained.

Scope and implementation

All production changes are in the Axios generator and templates. ModelUtils and the shared OpenAPINormalizer are unchanged against master.

Axios registers a generator-specific normalizer through the existing NORMALIZER_CLASS mechanism. It protects explicitly typed primitive compositions before generic normalization can mistake untyped predicates for null schemas or replace the parent with a child. Existing user-supplied normalizer classes can still override the default.

  • The fallback accepts untyped type-specific assertions and annotations, optionally alongside bare null branches. It keeps the predicates and enclosing enum/length constraints. Enum parents retain their enum representation.

  • Only assertions known to accept null without an explicit type enter this path. References, enum/const alternatives, logical applicators, mixed primitive types and unknown keywords are not treated as validation-only predicates.

  • Nullability intersects the parent's type/enum constraints with composition semantics. For example, null matches both branches of oneOf: [{pattern: ...}, {type: 'null'}], so even a [string, 'null'] parent must exclude it. Type-array ordering does not matter.

  • Axios renders primitive aliases for the supported compositions, inline models, and the single-member wrappers used for nullable references.
  • These aliases approximate pattern/range predicates with their TypeScript primitive type; they do not implement runtime validation or exhaustive JSON Schema satisfiability.

    The shared normalizer must not be changed as part of this Axios fix: retaining validation-only oneOf globally made Fetch encode and decode {value: "letters"} as {value: {}}, even though both SDKs compiled. A committed Fetch regression fixture/assertion protects scalar conversion. More general fixes for object-plus-null, untyped logical compositions, array constraints, and const/not combinations require a separate cross-generator change.

    Validation

  • Full Maven reactor ./mvnw -B package -Dmaven.javadoc.skip=true passes with JDK 21: 5,888 tests, zero failures/errors, 18 skipped.

  • After the final change to support immutable alternative lists, the generator/core/CLI package build and focused ModelUtils, normalizer, Axios and Fetch suites pass: 229 tests, zero failures/errors, two existing skips.

  • Regression coverage includes OAS 3.0/3.1, combined/separate models, single/multiple predicates, inline/required properties, numeric ranges, nullable references, parent enum/length constraints, contains + null under a string parent, null-first type arrays, and nullable oneOf overlap. The schema expectations for the new 3.1 counterexamples were independently checked with a JSON Schema validator.

  • Strict TypeScript 5.9.3 contracts pass in all four version/layout combinations, including actual SDK method parameters and results. Negative checks reject numbers, inappropriate nulls, and values outside the parent enum.

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

  • On primitive-composition-runtime.yaml, both baseline and revised Fetch SDKs pass strict compilation, model JSON conversion, and API request/response tests for alphabetic and numeric strings. Both Python SDKs pass model JSON conversion and actual HTTP request/response roundtrips against a local test server.

  • On the full OAS 3.0/3.1 primitive-anyof-validation.yaml fixtures, every generated Fetch/Python source file is byte-identical to the baseline (the baseline has master-identical shared normalizer and generator sources). These larger SDKs are not fully working: Fetch has the same two pre-existing missing FromJSON/ToJSON errors in each version; Python rejects the 3.0 primitive model input and emits invalid enum syntax in 3.1 on both versions of the generator. The passing runtime checks above use the isolated fixture and do not imply those existing issues are fixed.

  • All 836 sample configurations regenerate with no changes. All generator documentation exports with no changes. git diff --check passes.
  • PR checklist

  • Read the contribution guidelines.

  • Run the full Maven reactor package build and the final focused checks 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 #25637. Schemas with a primitive type and validation-only anyOf/oneOf branches (pattern, range, length, etc.) now generate the primitive type alias in typescript-axios instead of an empty interface, so methods no longer accept numbers/null where a string is expected. A Hostname with type: string and pattern-only branches now emits export type Hostname = string, and required non-nullable properties are typed Hostname rather than nullable. Code that relied on the previous number/null assignments will now get TypeScript errors.

    The fix is isolated to typescript-axios by registering a generator-specific normalizer through the NORMALIZER_CLASS mechanism; the shared OpenAPINormalizer and other generators such as typescript-fetch are unchanged.

    Changes

  • Validation-only, annotation-only, enum, and const branches are no longer treated as null schemas or discarded during normalization, so their constraints and metadata survive.

  • Removing a null alternative no longer widens an explicitly typed parent to nullable.

  • OpenAPI 3.1 nullable type arrays on anyOf parents are normalized to nullable.

  • Primitive aliases are emitted for such models, including inline models and single-member allOf wrappers used for nullable references.

  • Enum, const, mixed-type, and other composed constraints are not replaced by the primitive fallback.
  • <sup>Written for commit 5acbb1603625ffe3e871b1da589d46dd4cb438f6. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/25638?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: 3022m
    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 #25638"
    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%