| name | orval |
| description | Generate type-safe API clients, TanStack Query/SWR hooks, Zod schemas, MSW mocks, Hono server handlers, MCP servers, and SolidStart actions from OpenAPI specs using Orval. Covers all clients (React/Vue/Svelte/Solid/Angular Query, Fetch, Axios), custom HTTP mutators, authentication patterns, NDJSON streaming, programmatic API, and advanced configuration. |
Orval - OpenAPI to TypeScript Code Generator
Orval generates type-safe TypeScript clients, hooks, schemas, mocks, and server handlers from OpenAPI v3/Swagger v2 specifications.
Quick Start
Installation
npm install orval -D
Minimal Configuration
import { defineConfig } from 'orval';
export default defineConfig({
petstore: {
input: {
target: './petstore.yaml',
},
output: {
target: './src/api/petstore.ts',
schemas: './src/api/model',
client: 'react-query',
},
},
});
Run
npx orval
npx orval --config ./orval.config.ts
npx orval --project petstore
npx orval --watch
Choosing Your Setup
Client Selection Guide
| Use Case | Client | httpClient | Notes |
|---|
| React with server state | react-query | fetch or axios | TanStack Query hooks |
| Vue 3 with server state | vue-query | fetch or axios | TanStack Query for Vue |
| Svelte with server state | svelte-query | fetch or axios | TanStack Query for Svelte |
| SolidJS standalone app | solid-query | fetch or axios | TanStack Query for Solid |
| SolidStart full-stack | solid-start | native fetch | Uses query()/action() primitives |
| Angular with signals | angular-query | angular | Injectable functions, signal reactivity |
| Angular traditional | angular | — | HttpClient services |
| React with SWR | swr | fetch or axios | Vercel SWR hooks |
| Lightweight / Edge | fetch | — | Zero dependencies, works everywhere |
| Node.js / existing Axios | axios-functions | — | Factory functions (default) |
| Axios with DI | axios | — | Injectable Axios instance |
| Validation only | zod | — | Zod schemas, no HTTP client |
| Backend API server | hono | — | Hono handlers with Zod validation |
| AI agent tools | mcp | — | Model Context Protocol servers |
Mode Selection Guide
single — Everything in one file. Best for small APIs.
split — Separate files: petstore.ts, petstore.schemas.ts, petstore.msw.ts. Good for medium APIs.
tags — One file per OpenAPI tag + shared schemas. Organizes by domain.
tags-split — Folder per tag with split files. Best for large APIs. Recommended.
httpClient Option
For react-query, vue-query, svelte-query, and swr clients:
output: {
client: 'react-query',
httpClient: 'fetch',
}
For angular-query:
output: {
client: 'angular-query',
httpClient: 'angular',
}
Configuration Reference
Config Structure
import { defineConfig } from 'orval';
export default defineConfig({
[projectName]: {
input: InputOptions,
output: OutputOptions,
hooks: HooksOptions,
},
});
Multiple projects can share the same config file with different input/output settings.
Input Options
input: {
target: './spec.yaml',
override: {
transformer: './transform.js',
},
filters: {
mode: 'include',
tags: ['pets', /health/],
schemas: ['Pet', /Error/],
},
parserOptions: {
headers: [
{
domains: ['api.example.com'],
headers: {
Authorization: 'Bearer YOUR_TOKEN',
'X-API-Key': 'your-api-key',
},
},
],
},
}
Output Options
output: {
target: './src/api/endpoints.ts',
client: 'react-query',
httpClient: 'fetch',
mode: 'tags-split',
schemas: './src/api/model',
operationSchemas: './src/api/params',
workspace: 'src/',
fileExtension: '.ts',
namingConvention: 'camelCase',
indexFiles: true,
clean: true,
prettier: true,
biome: true,
headers: true,
baseUrl: '/api/v2',
mocks: true,
docs: true,
allParamsOptional: true,
urlEncodeParameters: true,
optionsParamRequired: false,
propertySortOrder: 'Specification',
tsconfig: './tsconfig.json',
override: { ... },
}
Multiple API Specs
export default defineConfig({
petstoreV1: {
input: { target: './specs/v1.yaml' },
output: { target: 'src/api/v1', client: 'react-query' },
},
petstoreV2: {
input: { target: './specs/v2.yaml' },
output: { target: 'src/api/v2', client: 'react-query' },
},
});
Filter Endpoints
input: {
target: './spec.yaml',
filters: {
mode: 'include',
tags: ['pets'],
},
}
Detailed Guides
When the user's question involves a specific topic below, read the corresponding file from this skill's directory.
| Topic | File | Load when user asks about... |
|---|
| TanStack Query / SWR | tanstack-query.md | React Query, Vue Query, Svelte Query, Solid Query, SWR, query hooks, invalidation, infinite queries, suspense, prefetch |
| Angular | angular.md | Angular Query, Angular HttpClient, signals, inject functions, Angular services, providedIn |
| SolidStart | solid-start.md | SolidStart, @solidjs/router, query(), action(), createAsync, revalidate |
| Custom HTTP / Auth | custom-http-clients.md | Custom mutator, authentication, tokens, interceptors, custom fetch/axios, baseURL, hook-based mutator |
| Zod Validation | zod-validation.md | Zod schemas, validation, runtime validation, coerce, strict, preprocess |
| Mocking / MSW | mocking-msw.md | MSW mocks, testing, test setup, faker, Vitest, mock handlers, useExamples |
| Hono Server | hono.md | Hono handlers, zValidator, composite routes, context types, server-side generation |
| Advanced Config | advanced-config.md | Type generation, enums, per-operation overrides, FormData, JSDoc, params serializer, full example |
| Tooling / Workflow | tooling-workflow.md | Programmatic API, transformers, hooks, NDJSON streaming, MCP, afterAllFilesWrite |
OpenAPI Specification Best Practices
- Use unique
operationId for every operation — Orval uses these for function and hook names
- Define reusable schemas in
components/schemas — reduces duplication in generated types
- Use tags to group operations — works with
tags and tags-split modes
- Define response types for all operations — enables full type safety
- Mark required fields — affects optional/required in generated TypeScript interfaces
- Use
x-enumNames for numeric enums — generates readable const names
- Provide
example values — used by mock generation when useExamples: true
- Use
application/x-ndjson content type for streaming endpoints — enables typed NDJSON generation
CLI Reference
orval
orval --config ./api/orval.config.ts
orval --project petstore
orval --watch
orval --watch ./src
orval --clean
orval --prettier
orval --biome
orval --tsconfig ./src/tsconfig.json
orval --mode split
orval --client react-query
orval --mock
orval --input ./spec.yaml --output ./api.ts
Resources