Orval ↗
Generates fully-typed API clients (Axios, Fetch, React Query, and more) from an OpenAPI spec. Setting the client to "zod" outputs Zod schemas instead of plain TypeScript interfaces.
Maintaining handwritten Zod schemas for a large API is tedious, and they drift from the spec whenever the API changes. Orval re-generates them from the OpenAPI spec on demand.
import { defineConfig } from 'orval';
export default defineConfig({
petstore: {
input: './openapi.yaml',
output: {
target: './src/api/petstore.ts',
// 'zod' mode emits Zod schemas instead of TS interfaces
client: 'zod',
},
},
});// src/api/petstore.ts (generated — do not edit)
import { z } from 'zod';
export const petSchema = z.object({
id: z.number().int(),
name: z.string(),
status: z.enum(['available', 'pending', 'sold']).optional(),
});
export type Pet = z.infer<typeof petSchema>;