Why Use Validators?
While TypeScript provides compile-time type safety, validators add runtime safety:- Runtime validation: Ensure data from external sources matches your expected types
- Type inference: Generate TypeScript types from validation schemas
- API contract enforcement: Validate requests and responses against your OpenAPI spec
- Developer experience: Get instant feedback when data doesn’t match expectations
Available Validator Libraries
OpenAPI TypeScript supports multiple validation libraries:Zod
TypeScript-first schema validation with static type inference
Valibot
Modular and lightweight schema library with excellent bundle size
How It Works
Validator plugins generate schemas from your OpenAPI specification that can validate:- Definitions - Reusable component schemas
- Requests - Request bodies, query parameters, path parameters, and headers
- Responses - Response bodies and status codes
- Webhooks - Webhook payload schemas
Quick Start
Add a validator plugin to your configuration:Configuration Options
Both validator plugins share similar configuration patterns:Schema Generation
Control which schemas are generated:Naming Patterns
Customize generated schema names:Casing Conventions
Set casing for generated identifiers:Usage Examples
Validating API Responses
Validating Request Data
Type Inference
Generate TypeScript types from your validation schemas:Next Steps
Zod Plugin
Learn about Zod-specific features and configuration
Valibot Plugin
Learn about Valibot-specific features and configuration