Skip to content

[typescript-fetch] Preserve nullable primitive oneOf branches - #25100

Open
simPod wants to merge 1 commit into
OpenAPITools:masterfrom
simPod:fix/typescript-fetch-nullable-oneof
Open

simPod wants to merge 1 commit into
OpenAPITools:masterfrom
simPod:fix/typescript-fetch-nullable-oneof

Conversation

@simPod

@simPod simPod commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Context

A nullable primitive branch in an OpenAPI 3.0 oneOf loses null in the generated TypeScript type. This affects both the separate-model and withoutRuntimeChecks output modes.

For example:

oneOf:
  - type: string
    nullable: true
  - type: number

The generated declaration is number | string, although this schema also accepts null.

Root cause

The oneOf type-name strings do not retain branch nullability. The corresponding composed-schema properties still contain it.

Decision

Count nullable branches from the composed-schema properties and add null to the generated type union when exactly one branch is nullable. This fixes the type metadata without a template override or a new generator option.

Consequences

Nullable primitive unions include null. Unions with zero or two nullable primitive branches keep their non-null declaration, consistent with the exactly-one matching rule of oneOf. Nullable array elements do not make the array itself nullable.

cc @joscha


Summary by cubic

Fixes the TypeScript fetch generator so nullable primitive oneOf branches preserve null in the generated union type.

  • Adds null to the union only when exactly one branch is nullable, matching the oneOf semantics.
  • Nullable array items don't make the containing array itself nullable.

Written for commit 80e2602. Summary will update on new commits.

Review in cubic

@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 3 files

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.

1 participant