fix: anyOf with sibling properties generates intersection instead of …#2608
fix: anyOf with sibling properties generates intersection instead of …#2608wotan-allfather wants to merge 1 commit intoopenapi-ts:mainfrom
Conversation
…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
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 1c103e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
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? |
…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
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)