dog-schema-validator
Advanced validation utilities for DogRS schemas - runtime validation, constraints, and error handling
dog-schema-validator provides advanced validation capabilities that extend dog-schema with runtime validation, custom constraints, and comprehensive error handling for production applications.
Features
- Runtime validation - Validate data against schemas at runtime
- Custom constraints - Define complex validation rules
- Detailed error reporting - Comprehensive validation error messages
- Performance optimized - Fast validation for high-throughput applications
- Integration ready - Works seamlessly with dog-schema and dog-core
Quick Start
Add to your Cargo.toml:
[]
= "0.1.3"
Basic Usage
use ;
use Schema;
use ;
// Create validation rules
let rules = new
.field
.min_length
.max_length
.pattern
.field
.email
.required
.field
.range;
// Validate data
let user_data = json!;
match rules.validate
Advanced Validation Rules
String Validation
use ValidationRules;
let rules = new
.field
.min_length
.max_length
.pattern
.not_empty
.field
.min_length
.contains_uppercase
.contains_lowercase
.contains_digit
.contains_special_char;
Numeric Validation
let rules = new
.field
.positive
.decimal_places
.range
.field
.integer
.min
.max;
Collection Validation
let rules = new
.field
.array
.min_items
.max_items
.unique_items
.each_item;
Custom Validators
Create complex validation logic:
use ;
;
let rules = new
.field
.string
.one_of
.custom_validator;
Conditional Validation
Validate fields based on other field values:
let rules = new
.field
.string
.required
.field
.when
.pattern
.when
.pattern
.when
.pattern;
Error Handling
Comprehensive error reporting with field paths:
use ;
match rules.validate
Integration with DogRS Services
Use with dog-core services for automatic validation:
use ;
use ;
;
Performance Features
Validation Caching
use CachedValidator;
let validator = new
.with_cache_size
.with_ttl;
// Repeated validations of similar data structures are cached
let result = validator.validate?;
Async Validation
use AsyncValidator;
let validator = new;
// For I/O bound validations (database lookups, API calls)
let result = validator.validate_async.await?;
Validation Middleware
Use with dog-axum for automatic request validation:
use ValidatedJson;
use ValidationRules;
async
Architecture
dog-schema-validator extends the DogRS ecosystem:
┌─────────────────┐
│ Your App │ ← Business logic with validated data
├─────────────────┤
│ dog-axum │ ← HTTP validation middleware
├─────────────────┤
│ dog-schema- │ ← Advanced validation rules
│ validator │
├─────────────────┤
│ dog-schema │ ← Schema definitions
├─────────────────┤
│ dog-core │ ← Core service traits
└─────────────────┘
Examples
See dog-examples/ for complete applications:
- blog-axum - REST API with comprehensive validation
- social-typedb - Social network with user data validation
License
MIT OR Apache-2.0
Made by Jitpomi