-
-
Notifications
You must be signed in to change notification settings - Fork 609
Fix prefixItems / minItems / maxItems tuple generation #2053
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
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! |
* Simplify minItems / maxItems tuple generation Closes openapi-ts#2048
* Simplify minItems / maxItems tuple generation Closes openapi-ts#2048
* Simplify minItems / maxItems tuple generation Closes openapi-ts#2048
* Simplify minItems / maxItems tuple generation Closes openapi-ts#2048
* Simplify minItems / maxItems tuple generation Closes openapi-ts#2048
Changes
Closes #2048
transformArraySchemaObjectmethoditemsis arrayminItems*maxItemsunionsminItems&maxItemsunionsprefixItemstupleprefixItemstype members inminItems&maxItemstuplesprefixItemstuple with nominItems/maxItemsconstraintsitemsis arrayitems: oneOf: [{ type: 'string' }, { type: 'number' }]minItems+maxItemsschema generating empty tuple, as outlined in--array-lengthwithminItems: 1generates empty array #2048arrayLengthandimmutableoptions, andprefixItems,minItems,maxItemsschemasThe 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.readonlyExamples
Here's a simple schema, and the before+after generated types.
☕ minItems empty tuple
📖 readonly spread type
🙉 preserve
prefixItemsThe same schema with the
arrayLength: trueoption set generates quite different types.How to Review
readonlyspread member is acceptable (this may qualify as a breaking change)itemsis array is acceptableprefixItemsschemas is acceptableprefixItemsandarrayLengthin combination to generate the desired array-of-tuplesChecklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)