fix(typescript-axios): preserve primitive anyOf types and nullability #25638
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.344
Real PR Conversation Timeline
1 comments
"Review active on #25638"
general
weight: 0.35
thekhegay
<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:
typescript-axiosgenerates 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 = stringand preserves the enclosing primitive type on properties and method signatures. Explicitly nullable schemas emitstring | nullwhen 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.
ModelUtilsand the sharedOpenAPINormalizerare unchanged against master.Axios registers a generator-specific normalizer through the existing
NORMALIZER_CLASSmechanism. 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.oneOf: [{pattern: ...}, {type: 'null'}], so even a[string, 'null']parent must exclude it. Type-array ordering does not matter.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
oneOfglobally 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
./mvnw -B package -Dmaven.javadoc.skip=truepasses with JDK 21: 5,888 tests, zero failures/errors, 18 skipped.contains + nullunder a string parent, null-first type arrays, and nullableoneOfoverlap. The schema expectations for the new 3.1 counterexamples were independently checked with a JSON Schema validator.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.primitive-anyof-validation.yamlfixtures, 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 missingFromJSON/ToJSONerrors 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.git diff --checkpasses.PR checklist
./bin/generate-samples.sh ./bin/configs/*.yamland inspect the diff../bin/utils/export_docs_generators.sh.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Fixes #25637. Schemas with a primitive type and validation-only
anyOf/oneOfbranches (pattern, range, length, etc.) now generate the primitive type alias intypescript-axiosinstead of an empty interface, so methods no longer accept numbers/null where a string is expected. AHostnamewithtype: stringand pattern-only branches now emitsexport type Hostname = string, and required non-nullable properties are typedHostnamerather than nullable. Code that relied on the previous number/null assignments will now get TypeScript errors.The fix is isolated to
typescript-axiosby registering a generator-specific normalizer through theNORMALIZER_CLASSmechanism; the sharedOpenAPINormalizerand other generators such astypescript-fetchare unchanged.Changes
anyOfparents are normalized to nullable.allOfwrappers used for nullable references.<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. -->