-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix prefixItems / minItems / maxItems tuple generation #2053
Conversation
🦋 Changeset detectedLatest commit: 68d9191 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 |
Account for immutable: true
This is amazing! To be honest this is the first time a contributor has made such an incremental improvement in the library that warranted a major version push. I’d like to get this merged, but the rest of the maintainers and myself would have to work a little bit more on the roadmap to 8.x because as of now it’s unknown. I’d like to strategize a little bit more before simply merging this and releasing a major version. But I don’t want this PR to just sit around, waiting for that to happen. So what I’ll propose doing for now is merging this into an Thank you! |
Changes
Closes #2048
transformArraySchemaObject
methoditems
is arrayminItems
*maxItems
unionsminItems
&maxItems
unionsprefixItems
tupleprefixItems
type members inminItems
&maxItems
tuplesprefixItems
tuple with nominItems
/maxItems
constraintsitems
is arrayitems: oneOf: [{ type: 'string' }, { type: 'number' }]
minItems
+maxItems
schema generating empty tuple, as outlined in--array-length
withminItems: 1
generates empty array #2048arrayLength
andimmutable
options, andprefixItems
,minItems
,maxItems
schemasThe previous union+tuples generation implementation was a little hair-ball, and difficult for me to parse, so I replaced it with a stepped implementation, returning early with results whenever possible.
readonly
, but not the union as a wholereadonly
, as well as its spread members.readonly
Examples
Here's a simple schema, and the before+after generated types.
☕ minItems empty tuple
📖 readonly spread type
🙉 preserve
prefixItems
The same schema with the
arrayLength: true
option set generates quite different types.How to Review
readonly
spread member is acceptable (this may qualify as a breaking change)items
is array is acceptableprefixItems
schemas is acceptableprefixItems
andarrayLength
in combination to generate the desired array-of-tuplesChecklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)