Validation Architecture
ZeroStarter uses Zod for runtime type validation and schema definition. Schemas are integrated with OpenAPI documentation viahono-openapi.
Schema Definition
Define reusable schemas for data models (routers/v1.ts:8-27):
Session Schema
User Schema
OpenAPI Integration
Schemas are converted to OpenAPI specs using theresolver function from hono-openapi.
Response Schema Documentation
Define response schemas in route descriptions (routers/v1.ts:50-58):
resolver function converts Zod schemas to JSON Schema for OpenAPI.
Metadata for Documentation
Add metadata to schema fields for better API docs:Health Check Response Schema
Inline schema definition for simple responses (index.ts:68-78):
Error Response Schemas
ZeroStarter uses consistent error response formats.Validation Errors
Zod validation errors are automatically formatted (lib/error.ts:7-14):
Standard Error Format
All errors follow the same structure:VALIDATION_ERROR- Request validation failed (400)UNAUTHORIZED- No valid session (401)FORBIDDEN- Insufficient permissions (403)NOT_FOUND- Resource not found (404)TOO_MANY_REQUESTS- Rate limit exceeded (429)INTERNAL_SERVER_ERROR- Unhandled server error (500)
Request Validation
Validate incoming request data using Zod schemas:Query Parameter Validation
Validate query strings:Path Parameter Validation
Validate URL parameters:Combining Multiple Validators
Validate different parts of the request:Schema Composition
Reuse and extend schemas:TypeScript Type Inference
Extract TypeScript types from Zod schemas:Custom Validation Rules
Add custom validation logic:Documenting Full Routes
Complete example with validation and documentation:Next Steps
- Routing - Learn about route structure
- Middleware - Add authentication and rate limiting