Installation
Install the required dependencies:Configuration
Add the Valibot plugin to youropenapi-ts.config.ts:
openapi-ts.config.ts
Schema Generation
Definitions
Generate schemas for reusable component definitions:valibot.gen.ts
Requests
Generate validators for API request data (body, query, path, headers):valibot.gen.ts
Responses
Generate validators for API responses:valibot.gen.ts
Webhooks
Generate validators for webhook payloads:Valibot Pipes
Valibot uses a pipe-based architecture for transformations and validations. The plugin generates schemas using Valibot’s pipe syntax:Metadata Support
Enable Valibot metadata for additional schema information:Usage Examples
Validating API Requests
Validating API Responses
Async Validation
Type Inference
Form Validation with React
String Formats
Valibot automatically generates appropriate validators for OpenAPI string formats:
Example:
Advanced Configuration
Custom Naming Patterns
Use functions for dynamic naming:Selective Schema Generation
Disable specific schema categories:Global Configuration
Bundle Size Benefits
Valibot is designed to be tree-shakable and has a smaller bundle size compared to other validation libraries:- Modular architecture: Only import what you need
- Tree-shakable: Unused validators are removed during bundling
- Minimal runtime: Core functionality is lightweight
- Pipe-based composition: Efficient schema composition
Type Reference
The Valibot plugin exports these configuration types:Migration from Zod
If you’re migrating from Zod to Valibot:- Zod
- Valibot
- Valibot uses
v.pipe()for chaining validators instead of method chaining - Valibot uses
InferOutputinstead ofinfer - Valibot’s parse result uses
outputinstead ofdata - Valibot’s validation issues use a different structure
Related
Validators Overview
Learn about validator plugins and their benefits
Zod Plugin
Alternative validator with method chaining syntax
Valibot Documentation
Official Valibot library documentation