Skip to main content
OpenAPI TypeScript supports generating runtime validation schemas from your OpenAPI specifications. Validators provide runtime type safety by validating data against your API contracts at runtime, catching errors before they reach your application logic.

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:
  1. Definitions - Reusable component schemas
  2. Requests - Request bodies, query parameters, path parameters, and headers
  3. Responses - Response bodies and status codes
  4. Webhooks - Webhook payload schemas

Quick Start

Add a validator plugin to your configuration:
Generate your schemas:

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:
Or enable automatic type generation:

Next Steps

Zod Plugin

Learn about Zod-specific features and configuration

Valibot Plugin

Learn about Valibot-specific features and configuration