Skip to content

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

Open
Justineo wants to merge 1 commit into
OpenAPITools:masterfrom
Justineo:fix/typescript-axios-oneof-properties
Open

Justineo wants to merge 1 commit into
OpenAPITools:masterfrom
Justineo:fix/typescript-axios-oneof-properties

Conversation

@Justineo

@Justineo Justineo commented Nov 12, 2026 •

Copy link
Copy Markdown
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 TypeScriptAxiosClientCodegenTest cases 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-axios succeeds with no documentation changes.
  • The standalone fixture passes the generator's spec validation; its unreferenced discriminator example produces one unused-model recommendation.
  • git diff --check passes.

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 oneOf unions like Submission stay unchanged.
  • Discriminator unions keep their mapping expression inside the intersection.
  • Regenerating all Axios samples changes only two Fruit declarations, which now include their previously omitted optional color property.

Written for commit c457e90. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 10 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][typescript-axios] oneOf models drop sibling properties

1 participant