Skip to content

Fix array minItems/maxItems bugs#2546

Open
simonsolnes wants to merge 2 commits intoopenapi-ts:mainfrom
simonsolnes:solnes/fix-minmax-bugs
Open

Fix array minItems/maxItems bugs#2546
simonsolnes wants to merge 2 commits intoopenapi-ts:mainfrom
simonsolnes:solnes/fix-minmax-bugs

Conversation

@simonsolnes
Copy link

Changes

Fix bugs related to minItems and maxItems when using --array-length

Issue: #1781

Fix incorrectly generating tuples from 0 to (max-min) elements instead of min to max elements.

For example, minItems: 1, maxItems: 3 was producing [] | [T] | [T, T] instead of [T] | [T, T] | [T, T, T].

When an array's items was also an array type with minItems equal to maxItems,
the generated TypeScript was getting incorrectly double-nested
(e.g. string[][] instead of string[]).

How to Review

The tests shows the expected results

Checklist

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

… algorithm

The loop was incorrectly generating tuples from 0 to (max-min) elements
instead of min to max elements. For example, minItems: 1, maxItems: 3
was producing [] | [T] | [T, T] instead of [T] | [T, T] | [T, T, T].
@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 44eb2fc

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

This PR includes changesets to release 2 packages
Name Type
openapi-typescript Patch
swr-openapi 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

@netlify
Copy link

netlify bot commented Dec 10, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 44eb2fc

@simonsolnes simonsolnes marked this pull request as ready for review December 10, 2025 22:16
@simonsolnes simonsolnes requested a review from a team as a code owner December 10, 2025 22:16
@simonsolnes simonsolnes requested a review from gzm0 December 10, 2025 22:16
@drwpow
Copy link
Contributor

drwpow commented Feb 8, 2026

Thank you! Would you mind adding a changeset for this (see comment)?

… flag

When an array's items was also an array type with minItems equal to maxItems,
the generated TypeScript was getting incorrectly double-nested
(e.g. string[][] instead of string[]).

The issue was that the code checked if itemType was already an array/tuple
to skip wrapping, but this incorrectly skipped wrapping for standard arrays
when the nested transform happened to return an array type. Now we track
whether the current schema defines a tuple (via prefixItems) separately.
@simonsolnes simonsolnes force-pushed the solnes/fix-minmax-bugs branch from 2c1266e to 44eb2fc Compare March 12, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants