-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add length constraints to ZodTuple for JSON Schema #5399
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
WalkthroughThis change adds length-based constraints to the ZodTuple schema by introducing four new chainable methods: Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 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:
🧠 Learnings (3)📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
🧬 Code graph analysis (1)packages/zod/src/v4/classic/schemas.ts (2)
🔇 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 |
This pull request enhances
ZodTupleby 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 lacksminItemsandmaxItemsproperties. 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.