Orval is a robust TypeScript client generator for OpenAPI/Swagger specifications, designed to automate the creation of type-safe API clients. It supports generating clients with various data fetching libraries, including React Query, Svelte Query, Axios, and Fetch, and can also generate mock data using Faker.js. The current stable version is 8.8.0, with minor and patch releases occurring frequently to incorporate new features (like `useSetQueryData` helpers), address bugs, and maintain compatibility with evolving ecosystem standards. Orval distinguishes itself through extensive customization options via its configuration file, allowing developers to precisely tailor the generated output for specific frameworks and architectural patterns, and by deeply integrating with OpenAPI schema validation and TypeScript type checking workflows to ensure high-quality, maintainable code.
npm install orvalVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic Orval configuration for generating a React Query client with mock data and a custom Axios mutator, then how to run it via an npm script.
Install `@faker-js/faker` as a dev dependency: `npm install -D @faker-js/faker` or `yarn add -D @faker-js/faker`.
Ensure `prettier` is installed in your project: `npm install -D prettier` or `yarn add -D prettier`.
Upgrade your Node.js environment to version 18.17.0 or newer. Consider using a Node Version Manager (nvm) for easy switching.
After upgrading Orval, carefully review generated client code for import resolution issues or type discrepancies. Refer to the Orval changelog for specific migration details for each minor release.
Install Faker.js: `npm install -D @faker-js/faker`.
Verify the `input` path in your Orval configuration, ensuring the file exists and the path is correct relative to where Orval is executed.
Create an `orval.config.ts` or `orval.config.js` file in your project root or specify its path using the `--config` flag.
Ensure your `orval.config.ts` uses ESM import syntax (`import { defineConfig } from 'orval';`) and your `tsconfig.json`'s `module` option is set appropriately (e.g., `"ESNext"` or `"NodeNext"`).