Universal Validation System
Use any validation library you prefer. MoroJS supports Zod, Joi, Yup, class-validator, or custom functions—all with the same consistent API.
On this page
Use Any Validation Library
Don't like Zod? Use Joi. Prefer Yup? That works too.
Same API, your choice of library.
Supported Libraries
TypeScript-first, zero dependencies (default)
Mature, feature-rich validation
Simple, lightweight validation
Decorator-based validation
Or write your own custom validation functions
Why Universal Validation Matters
Don't rewrite your validation logic. Use what you already know.
Without universal support, you're locked into one library or forced to rewrite everything.
Without Universal Support
- •Locked into one validation library
- •Rewriting schemas when switching
- •Team members forced to learn new syntax
- •No flexibility for different use cases
With MoroJS
- •Use any validation library you prefer
- •Same consistent API across all libraries
- •Team uses what they already know
- •Mix and match as needed
It's This Easy
Use your preferred library. Same API, different syntax.
Zod (default) - works directly
typescript
Why It Makes Sense
Flexible
Use the validation library your team knows best. No forced migrations.
Consistent
Same API regardless of library. Learn once, use everywhere.
Powerful
Mix libraries or write custom validators. Full control.
How It Works
MoroJS uses universal adapters to support any validation library. Define your schema using your preferred library's syntax, and MoroJS handles the rest—validation, error handling, and type inference.
Validation Libraries
Zod (Default) - Works Directly
typescript
Joi - Via Adapter
typescript
Yup - Via Adapter
typescript
Class Validator - Via Adapter
typescript
Custom Validation Functions
typescript
Query Parameter Validation
typescript
Advanced Patterns
Nested Objects and Arrays
typescript
Conditional Validation
typescript
Custom Validation with Refinements
typescript
Schema Composition and Reuse
typescript
Schema Transformations
typescript
Error Handling
MoroJS automatically handles validation errors and returns structured error responses.
Automatic Error Responses
json
Custom Error Handling
typescript
Best Practices
Do
- • Use descriptive error messages
- • Create reusable base schemas
- • Validate all external inputs
- • Use transformations for data cleaning
- • Define response schemas for documentation
- • Use z.infer for type extraction
Don't
- • Skip validation for "trusted" inputs
- • Use overly complex nested schemas
- • Ignore validation error details
- • Validate the same data multiple times
- • Use any types instead of proper schemas
- • Forget to handle edge cases