Get Started ​
WARNING
This package is in initial development. The interface might change before it becomes stable. We encourage you to leave feedback on GitHub.
@hey-api/openapi-ts is an OpenAPI to TypeScript codegen trusted more than 700k times each month to generate reliable API clients and SDKs.
Features ​
- works with CLI, Node.js 18+, or npx
- supports OpenAPI 2.0, 3.0, and 3.1 specifications
- supports JSON and YAML input files
- generates TypeScript interfaces and SDKs
- Fetch API, Axios, Angular, Node.js, and XHR clients available
- plugin ecosystem to reduce third-party boilerplate
Quick Start ​
The fastest way to use @hey-api/openapi-ts
is via npx
npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client -c @hey-api/client-fetch
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the Output page.
Before you can make API requests with the client you've just created, you need to install @hey-api/client-fetch
and configure it. Let's start by declaring your dependencies.
Installation ​
npm install @hey-api/client-fetch && npm install @hey-api/openapi-ts -D
pnpm add @hey-api/client-fetch && pnpm add @hey-api/openapi-ts -D
yarn add @hey-api/client-fetch && yarn add @hey-api/openapi-ts -D
bun add @hey-api/client-fetch && bun add @hey-api/openapi-ts -D
We recommend pinning an exact version so you can safely upgrade when you're ready. This package is in initial development and its API might change before v1.
CLI ​
Most people run @hey-api/openapi-ts
via CLI. To do that, add a script to your package.json
file which will make openapi-ts
executable through script.
"scripts": {
"openapi-ts": "openapi-ts"
}
The above script can be executed by running npm run openapi-ts
or equivalent command in other package managers. Next, we need to create a configuration file and move our options from Quick Start to it.
Node.js ​
You can also generate clients programmatically by importing @hey-api/openapi-ts
in a TypeScript file.
import { createClient } from '@hey-api/openapi-ts';
createClient({
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: 'src/client',
});
Configuration ​
It is a good practice to extract your configuration into a separate file. Learn how to do that and discover available options on the Configuration page.
Examples ​
You can view live examples on StackBlitz.
Sponsors ​
Love Hey API? Become our sponsor.