-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add length constraints to ZodTuple for JSON Schema #5369
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
base: main
Are you sure you want to change the base?
Conversation
@mohankumarelec is attempting to deploy a commit to the colinhacks Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe ZodTuple interface and constructor received four new validation methods for constraining tuple lengths. The Pre-merge checks✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (8)**/*.{js,jsx,ts,tsx,mjs,cjs,json}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,jsx,ts,tsx,mjs,cjs}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx,mjs,cjs}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,mjs,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)
Files:
**/*.{js,mjs,cjs,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/guidelines.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/zod-project-guide.mdc)
Files:
packages/zod/**📄 CodeRabbit inference engine (.cursor/rules/zod-project-guide.mdc)
Files:
🧬 Code graph analysis (1)packages/zod/src/v4/classic/schemas.ts (3)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@colinhacks , Can you please take a look into this PR and let me know if anything further required. Also please feel free to edit the PR if required. Thanks |
This pull request enhances
ZodTuple
by adding.min()
,.max()
,.length()
, and.nonempty()
methods, similar to those available onZodArray
.Currently, when a
z.tuple()
schema is converted to a JSON Schema, it lacksminItems
andmaxItems
properties. This results in an inaccurate schema that could, for example, incorrectly validate an empty array.By adding these length-based validation methods, the JSON Schema conversion now correctly includes the tuple's length constraints, ensuring more precise and reliable validation.