Skip to content

Conversation

@wotan-allfather
Copy link

…union

When a schema has both anyOf and properties at the same level, the properties should be intersected with the anyOf union, not included as another union member.

Before: { name?: string; } | Type1 | Type2
After: { name?: string; } & (Type1 | Type2)

This matches the OpenAPI spec semantics where sibling properties apply to all anyOf variants.

Closes #2380

Changes

What does this PR change? Link to any related issue(s).

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

…union

When a schema has both anyOf and properties at the same level, the properties
should be intersected with the anyOf union, not included as another union member.

Before: { name?: string; } | Type1 | Type2
After:  { name?: string; } & (Type1 | Type2)

This matches the OpenAPI spec semantics where sibling properties apply to all
anyOf variants.

Closes openapi-ts#2380
@wotan-allfather wotan-allfather requested a review from a team as a code owner February 10, 2026 18:03
@netlify
Copy link

netlify bot commented Feb 10, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1c103e7

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 1c103e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@drwpow
Copy link
Contributor

drwpow commented Feb 11, 2026

I’m not positive about this fix, this might be a breaking change for folks. W’ve had a LOT of back-and-forth over the years on how TypeScript unions actually behave in real code, because they’re not mutually-exclusive and do allow for anyOf semantics naturally.

Could you post a TS playground or proof that this is a better type? What is an error you used to get, but now don’t? What is the comparison of intersection vs unions? I think I’ll need to see more examples about real examples this fixes before accepting. Could you provide some please?

@drwpow drwpow added question Further information is requested openapi-ts Relevant to the openapi-typescript library labels Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

openapi-ts Relevant to the openapi-typescript library question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect typescript schema when using anyOf with properties

2 participants