fix(typescript-axios): preserve sibling properties in oneOf models
AI disclosure — Codex, GPT-6 Astra (High)
Codex investigated the generator, implemented this change, wrote the regression fixture and tests, ran the local validation 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 reproducing the bug against current master, distinguishing sibling properties from union-branch properties, checking generated SDK parameter and response types, and regenerating the affected samples.
The full project test matrix and samples for unrelated generators were not run locally. The additional TypeScript checks also exposed an existing discriminator/string-enum incompatibility, described below; this PR does not claim to fix it.
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 therefore loses its id, even though the schema requires it. Adding the field to the shared alternatives would also require it in request bodies.
This change generates the union intersected with its sibling properties:
// Before
export type Receipt = LinkSubmission | TextSubmission;
// After
export type Receipt = (LinkSubmission | TextSubmission) & {
'id': string;
'state': ReceiptStateEnum;
'owner': Owner;
'note'?: string | null;
};
The generator's vars list includes properties from the alternatives as well. The new template context selects only properties declared on the enclosing schema, so Submission = LinkSubmission | TextSubmission stays unchanged.
Property and enum rendering are shared with ordinary models. Separate model files import referenced sibling types. Discriminator unions retain their existing mapping expression inside the intersection.
Regenerating all 15 Axios sample configurations changes only two Fruit declarations, which now include their previously omitted optional color property.
Validation
- On unmodified master
df804ac9802fba0c51a64f8c3cb03191ed3dde2d, the four new cases fail because sibling fields are missing; the other 15 Axios tests pass. - After the fix, all 19
TypeScriptAxiosClientCodegenTestcases pass. The generator/core/CLI reactor package build succeeds with JDK 21:./mvnw -B -pl modules/openapi-generator-cli -am package \ -Dtest=TypeScriptAxiosClientCodegenTest \ -Dsurefire.failIfNoSpecifiedTests=false \ -Dmaven.javadoc.skip=true - The regression matrix covers combined/separate model files and constant-object/string enums. Assertions cover required/optional/nullable sibling properties, deprecation, sibling enum declarations, referenced-model imports, discriminator grouping, and exclusion of branch-only fields from the intersection.
- Additional strict TypeScript 5.9.3 checks verify that generated SDK methods accept either request alternative without response metadata and expose the sibling fields on their response. They also check missing-field errors and branch narrowing. Both model layouts pass with default enum generation. With
stringEnums=true, the checks for the non-discriminator request/response models pass in both layouts. ./bin/generate-samples.sh ./bin/configs/typescript-axios*succeeds for all 15 configurations../bin/utils/export_generator.sh typescript-axiossucceeds with no documentation changes.- The standalone fixture passes the generator's spec validation; its unreferenced discriminator example produces one unused-model recommendation.
git diff --checkpasses.
Existing limitation found during the additional compiler checks: with stringEnums=true, the literal discriminator intersection can reduce an enum-based alternative to never. The same failure reproduces with unmodified 7.27.0, before this change. That case is excluded from the passing string-enum compiler checks above and is outside this PR's scope.
PR checklist
- Read the contribution guidelines.
- Built the affected generator/CLI modules and ran the focused tests listed above.
- Regenerated and committed changes from all Axios sample configurations.
- Regenerated the Axios generator documentation.
- Run the full project
./mvnw clean package, regenerate samples for all generators, and export all generator documentation. These broader checks were not run locally. - Mention the TypeScript Axios technical committee member: @nicokoenig.
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
oneOfunions likeSubmissionstay unchanged. - Discriminator unions keep their mapping expression inside the intersection.
- Regenerating all Axios samples changes only two
Fruitdeclarations, which now include their previously omitted optionalcolorproperty.