Imported from orval-labs/orval (
skills/orval/SKILL.md) via skills.sh. Install upstream withnpx skills add orval-labs/orval --skill orval. Copyright stays with the author.
Orval — OpenAPI to TypeScript Code Generator
Orval generates type-safe TypeScript clients, hooks, validation schemas, mocks, and server handlers from OpenAPI v3/Swagger v2 specifications (ESM-only, Node >= 22.18).
Quick Start
npm install orval -D
# Optional peers when enabling formatter/mock below:
# npm install prettier msw @faker-js/faker -D
# (or bun add / pnpm add / yarn add)
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',
httpClient: 'fetch',
mode: 'tags-split',
formatter: 'prettier',
mock: true,
},
},
});
npx orval
npx orval --config ./orval.config.ts --project petstore
npx orval --outdated # CI check: exit 1 if generated files are stale
Client Selection Guide
| Use Case | client |
httpClient |
Notes |
|---|---|---|---|
| React server state | react-query |
fetch (default) | axios |
TanStack Query hooks |
| Vue 3 server state | vue-query |
fetch | axios |
TanStack Query for Vue |
| Vue 3 + Pinia | pinia-colada |
fetch | axios |
@pinia/colada queries & mutations |
| Svelte server state | svelte-query |
fetch | axios |
TanStack Query for Svelte |
| SolidJS standalone | solid-query |
fetch | axios |
TanStack Query for Solid |
| SolidStart full-stack | solid-start |
native fetch | @solidjs/router query() / action() |
| Angular signals + Query | angular-query |
angular | fetch | axios |
Signal-reactive inject* functions |
Angular services / httpResource |
angular |
— | HttpClient services and/or httpResource |
| React with SWR | swr |
fetch | axios |
Vercel SWR hooks |
| Lightweight / Edge | fetch |
— | Zero runtime deps, NDJSON streaming |
| Axios functions / DI | axios-functions | axios |
— | Functions (default) or injectable instance |
| Validation schemas only | zod | valibot | effect |
— | Standalone schema generation |
| Backend API server | hono |
— | Hono routes + handlers + Zod validation |
| AI agent tools | mcp |
— | Model Context Protocol servers |
Mode Selection Guide
single— Everything in one file (small APIs; recommended formcp).split— Separate client, schemas, and mock files.tags— One file per OpenAPI tag + shared schemas.tags-split— Folder per tag with split files (recommended for large APIs).tags-operations— One file per operation grouped inside tag folders. Supportsreact-query,svelte-query,vue-query,swr, andfetch(cannot be combined withoverride.fetch.httpClientInjection: 'factory').tags-operations-split— Folder per tag with per-operation split files. Same client restrictions astags-operations.
Key Input & Output Options
input.target— Path, URL, inline OpenAPI object, or ordered fallback array of paths/URLs (required). Supportsinput.filters(mode,tags,schemas,operationIds,includeUnreferencedSchemas),input.override.transformer, andinput.parserOptions(headers,externalRefs).input.unsafeDisableValidation— Disables OpenAPI validation; unsupported and may break generation on malformed specs.output.target— Entry output path (optional whenoutput.schemasis set for schema-only generation).output.schemas— Path string or{ path, type: 'typescript' | 'zod' | 'valibot' | 'effect', mode?, splitByTags? }. Useoutput.operationSchemasto split operation-derived params/responses.output.formatter—'prettier' | 'biome' | 'oxfmt'(replaces removedprettier/biomebooleans).output.mock—true(MSW + Faker), options object, or custom generator function (singularmock, notmocks).output.clean— Deletes existing files in the target/schemas directories before writing; never point it at a directory holding hand-written source.output.baseUrl— String,{ getBaseUrlFromSpecification: true, ... }, or{ runtime, imports }.- Other output flags:
workspace,fileExtension,namingConvention,indexFiles,headers,docs,allParamsOptional,urlEncodeParameters,optionsParamRequired,propertySortOrder,tsconfig,operationManifest,contentMapper,factoryMethods,tagsSplitDeduplication, andoverride(see guides below).
Detailed Guides
Read the matching guide in this directory when the user asks about a specific topic:
| Topic | File | Load when user asks about... |
|---|---|---|
| TanStack Query / Pinia Colada / SWR | tanstack-query.md | React/Vue/Svelte/Solid Query, Pinia Colada, SWR, invalidation, infinite queries, suspense, prefetch |
| Angular | angular.md | Angular Query, HttpClient, httpResource, signals, provideIn, DI baseUrl |
| SolidStart | solid-start.md | SolidStart, @solidjs/router, query(), action(), createAsync, revalidate |
| Custom HTTP / Auth | custom-http-clients.md | Custom mutator, auth tokens, interceptors, hook-based mutator, Fetch options, baseUrl |
| Schema Validation | zod-validation.md | Zod (v4/v3/mini), Valibot, Effect schemas, runtime validation, coerce, strict, preprocess |
| Mocking / MSW | mocking-msw.md | MSW mocks, Faker factories, Vitest setup, fixtures, useExamples, indexMockFiles |
| Hono Server | hono.md | Hono handlers, handlerGenerationStrategy, zValidator, composite routes, context types |
| Advanced Config | advanced-config.md | Enums, per-operation/tag overrides, FormData, JSDoc, operationManifest, contentMapper |
| Tooling / Workflow | tooling-workflow.md | MCP servers, NDJSON streaming, defineTransformer, hooks, programmatic ESM API |
CLI Reference
orval # Auto-discover orval.config.{ts,js,mjs}
orval --config ./orval.config.ts # Explicit config file
orval --project petstore # Run specific project(s)
orval --input ./spec.yaml --output ./api.ts # Direct generation without config
orval --client react-query --mode tags-split # Default client / mode (used when unset in config)
orval --mock # Enable MSW + Faker mocks
orval --clean # Clean output directories before writing
orval --formatter prettier # Format with prettier | biome | oxfmt
orval --watch ./specs # Watch mode
orval --tsconfig ./tsconfig.json # Custom tsconfig path
orval --outdated # Compare with existing files (CI; install prettier locally so it formats in-memory rather than falling back to CLI --write)
orval --fail-on-warnings # Exit 1 when warnings are emitted
orval --log-level warn # Log level (or --verbose / --quiet)
orval --print-content-mapper ./spec.yaml # Print TypeScript content mapper output
OpenAPI Spec Best Practices
- Unique
operationIdper operation for predictable function and hook names. - Reusable
components/schemasto minimize duplicated generated types. - Tags on operations when using
tags,tags-split,tags-operations, ortags-operations-split. x-enumNames/x-enumDescriptionsfor readable const enums, andexamplevalues foruseExamples: truemocks.application/x-ndjsonresponses for typed Fetch streaming.
