fix(openapi-typescript): enumValues generates valid TypeScript for oneOf/anyOf unions#2536
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 19638fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
Note: two tests will fail due to network errors (probably the original gist has been deleted). Nothing I can do on that front (they were already failing on main). |
Indeed, I've address this in a separate PR a few weeks back which is awaiting review: #2522 |
e904348 to
b33f83a
Compare
|
@sacha-c thanks, I've rebased so that tests can pass in CI now |
|
Thank you! Tests look good and this seems like an improvement. Could you please add a changeset (see comment) so we can version & release? Thank you! |
|
@drwpow done |
Changes
When using
enumValues: truewith OpenAPI schemas containingoneOf/anyOfunions, the generated TypeScript type paths would fail because properties might only exist on some union variants.Before (invalid TypeScript):
After (valid TypeScript):
The fix wraps property accesses after
oneOf/anyOfindices withExtract<>to narrow the union type before accessing variant-specific properties.This PR has been tested in a production environment with a custom build of openapi-typescript.
How to Review
I've added three tests:
Checklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)