Validation Hooks
The schema system provides two main validation hooks:validateData- Validates data forcreate,update, andpatchmethodsvalidateQuery- Validates query parameters for all methods
Basic Data Validation
Validation with Type Coercion
The default AJV instance enables type coercion, automatically converting data types:Method-Specific Validation
Using getDataValidator
Create different validators forcreate, update, and patch:
- Automatic Generation
- Custom Validators
- Single Hook
Query Validation
Validate query parameters to ensure safe database queries:Query Operators
ThequerySyntax helper creates schemas supporting Feathers query operators:
Custom Query Extensions
Extend query syntax with custom operators:Validation with Custom AJV
Use a custom AJV instance for advanced validation:Validation Errors
Validation failures throwBadRequest errors with detailed information:
Array Validation
ThevalidateData hook automatically handles array data:
Best Practices
Always validate at service boundaries
Always validate at service boundaries
Apply validation hooks to prevent invalid data from entering your system:
Use type coercion carefully
Use type coercion carefully
While convenient, type coercion can hide bugs. Consider disabling it for stricter validation:
Validate queries to prevent injection
Validate queries to prevent injection
Always validate queries, especially with SQL databases:
Use additionalProperties: false
Use additionalProperties: false
Prevent unexpected properties in your schemas:
Next Steps
Schema Resolvers
Learn how to transform data with resolvers
Schema Overview
Back to schema system overview