openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Fix prefixItems / minItems / maxItems tuple generation (#2053)

Open duncanbeevers opened this issue 9 months ago • 3 comments

🗣️ 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 / maxItems tuple generation
  • Introduces @total-typescript to accommodate Array.prototype.filter(Boolean) pattern
  • Extract subroutine for transforming array schema objects
  • Support items: false; prefixItems: … schemas; treat prefixItems as explicit tuple value.
  • Support items: […schemas], treating items as 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-members flag
  • [ ] Ensure ts-reset types don't affect published openapi-ts types
    • ts-reset behaviors should not be active in plain repo with openapi-ts dependency
    • Importing openapi-ts for programmatic use shouldn't start allowing ts-reset behaviors.
  • [ ] Ensure ts-reset types don't affect generated types
    • Importing openapi-typescript-generated types shouldn't start allowing ts-reset behavior.

🔧 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.

  1. New behavior gated behind the new --experimental-array-spread-members flag.
  2. Mutable spread members for array schemas when immutable: true is set
  3. Mutable tuples for array schemas with prefixItems when immutable: true is set
  4. Broken tuples (original #2048 problem)

Checklist

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

duncanbeevers avatar Feb 10 '25 18:02 duncanbeevers

Deploy Preview for openapi-ts failed.

Name Link
Latest commit b6d6fcb95174aff8c1bac221d66c44011381f200
Latest deploy log https://app.netlify.com/projects/openapi-ts/deploys/67b114e5d9f1790008b41e5d

netlify[bot] avatar Feb 10 '25 18:02 netlify[bot]

🦋 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

changeset-bot[bot] avatar Feb 10 '25 18:02 changeset-bot[bot]

@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?

gzm0 avatar Feb 19 '25 13:02 gzm0

This PR looks good to me! Sorry, minor conflict in the PR, but with that resolved + changeset this is good to merge! No notes 🙂

drwpow avatar May 10 '25 15:05 drwpow