openapi-typescript
openapi-typescript copied to clipboard
Fix prefixItems / minItems / maxItems tuple generation (#2053)
🗣️ Discussion
This PR is an extraction of some work that has already landed in the 8.x branch. This is my first step in porting those changes to the 7.x branch.
Closes #2048
Changes
- Simplify
minItems/maxItemstuple generation - Introduces @total-typescript to accommodate
Array.prototype.filter(Boolean)pattern - Extract subroutine for transforming array schema objects
- Support
items: false; prefixItems: …schemas; treatprefixItemsas explicit tuple value. - Support
items: […schemas], treatingitemsas explicit tuple value.
How to Review
- [ ] Ensure changes to newly-generated types are valid bug-fixes
- [ ] Ensure old behaviors are preserved where appropriate, to break fewer things when we release
- [ ] Ensure new behavior is gated behind
--experimental-array-spread-membersflag - [ ] Ensure ts-reset types don't affect published
openapi-tstypests-resetbehaviors should not be active in plain repo withopenapi-tsdependency- Importing
openapi-tsfor programmatic use shouldn't start allowingts-resetbehaviors.
- [ ] Ensure
ts-resettypes don't affect generated types- Importing
openapi-typescript-generated types shouldn't start allowingts-resetbehavior.
- Importing
🔧 Backwards-compatibility
In order to get a sense for the backwards-compatibility of this PR I pulled the full suite of tests from array.test.ts and ran them in main. Test output
Many test cases in this corpus cover behavior not-yet-tested in main, so this gives us a better sense of what will actually change.
Many of the new tests (expectedly) failed in this older context, and the errors fell into four categories.
- New behavior gated behind the new
--experimental-array-spread-membersflag. - Mutable spread members for array schemas when
immutable: trueis set - Mutable tuples for array schemas with prefixItems when
immutable: trueis set - Broken tuples (original #2048 problem)
Checklist
- [x] Unit tests updated
- [ ]
docs/updated (if necessary) - [ ]
pnpm run update:examplesrun (only applicable for openapi-typescript)
Deploy Preview for openapi-ts failed.
| Name | Link |
|---|---|
| Latest commit | b6d6fcb95174aff8c1bac221d66c44011381f200 |
| Latest deploy log | https://app.netlify.com/projects/openapi-ts/deploys/67b114e5d9f1790008b41e5d |
🦋 Changeset detected
Latest commit: 8a09dea9113d4f041f0a36ae9083e71cca1192a9
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 | Minor |
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 you have looked at the 8.x equivalent of this. Do you also want to take this one, or shall I give it a stab to review?
This PR looks good to me! Sorry, minor conflict in the PR, but with that resolved + changeset this is good to merge! No notes 🙂