Orval
Orval generates type-safe TypeScript clients, mocks, and validators from OpenAPI specifications, supporting major frameworks like React Query, Angular, and Vue Query to streamline development.
Orval is a powerful developer tool designed to transform OpenAPI v3 or Swagger v2 specifications into fully typed, production-ready TypeScript code. Built by developers for developers, Orval streamlines the communication contract between frontend and backend teams by automating the generation of API clients, models, and mock handlers. By converting manual and error-prone API integration work into automated processes, Orval allows teams to focus on shipping features rather than maintaining boilerplate code.
Functionality of the tool revolves around reading YAML or JSON-formatted OpenAPI specifications and generating tailored code assets that fit directly into modern JavaScript and TypeScript workflows. It offers high flexibility through configuration files, supporting a wide range of HTTP clients and data-fetching libraries including Axios and Fetch, as well as state management integration like React Query, Vue Query, Svelte Query, Solid Query, Angular, and SWR.
Some of the key features are:
- Type Safety: Automatic generation of TypeScript models and interfaces directly from API specifications to ensure end-to-end type safety.
- Framework Native: Seamless integration with popular frameworks including React, Angular, Vue, Svelte, and Solid.
- Mock Ready: Built-in support for MSW (Mock Service Worker) combined with Faker.js to generate realistic API responses for development and testing without a backend.
- Customizable Mutators: Highly configurable architecture allowing users to inject custom Axios instances or custom Fetch wrappers for specific authentication or interceptor needs.
- Flexible Configuration: Supports both CLI-based execution and robust configuration files (orval.config.ts) to manage complex multi-api projects.
- URL Generators: Automatically creates type-safe URL builder functions for complex API endpoints with query parameters.
Operationally, Orval is installed via npm, yarn, bun, or pnpm. Once installed, users define an input source (a local or remote OpenAPI file) and configure the output preferences. The tool can be run via the command line for quick tasks or invoked through a configuration file to integrate into CI/CD pipelines. As the specification evolves, Orval updates the generated client, ensuring the frontend stays perfectly in sync with the API contract. Developers can also utilize the browser-based playground to experiment with their schemas and see generated code output in real-time.
Some common use cases include:
- Rapid Frontend Development: Quickly bootstrap a type-safe client library when the API contract is ready, preventing the need to write manual fetch calls.
- Mock-Driven Testing: Enabling frontend teams to build and test entire application flows using MSW-generated handlers before the actual backend service is implemented.
- Large Scale API Management: Centralizing API client generation in large enterprise projects that consume multiple microservices through OpenAPI definitions.
- CI/CD Integration: Automatically regenerating API clients during build processes to ensure that any breaking changes in the API schema result in immediate TypeScript compilation errors in the frontend.
Comments
0Markdown is supported.