Skip to content

πŸš€ The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos

License

Notifications You must be signed in to change notification settings

hey-api/openapi-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hey API logo

OpenAPI TypeScript

πŸš€ The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.


MIT License Last commit CI status Number of open issues Test coverage

Demo Β β€’Β  Documentation Β β€’Β  Issues Β β€’Β  Roadmap Β β€’Β  npm


Features

  • runs in CLI, Node.js 18+, or npx
  • works with OpenAPI 2.0, 3.0, and 3.1
  • customizable types and SDKs
  • clients for your runtime (Fetch API, Axios, Next.js, Nuxt, etc.)
  • plugin ecosystem to reduce third-party boilerplate
  • custom plugins and custom clients
  • integration with Hey API Platform

Dashboard

Hey API is an ecosystem of products helping you build better APIs. Superpower your codegen and APIs with Hey API Platform.

Sign In to Hey API Platform.

Sponsors

Love Hey API? Become our sponsor.

Gold

Stainless logo
Generate best-in-class SDKs.
stainless.com

Silver

Scalar logo
scalar.com

Bronze

Kinde logo Cella logo

Quick Start

The fastest way to use @hey-api/openapi-ts is via npx

npx @hey-api/openapi-ts \
  -i https://get.heyapi.dev/hey-api/backend \
  -o src/client

Congratulations on creating your first client! πŸŽ‰ You can learn more about the generated files on the Output page.

Installation

npm

npm install @hey-api/openapi-ts -D

pnpm

pnpm add @hey-api/openapi-ts -D

yarn

yarn add @hey-api/openapi-ts -D

bun

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 will 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({
  input: 'https://get.heyapi.dev/hey-api/backend',
  output: 'src/client',
});

Configuration

@hey-api/openapi-ts supports loading configuration from any file inside your project root folder supported by jiti loader. Below are the most common file formats.

openapi-ts.config.ts

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://get.heyapi.dev/hey-api/backend',
  output: 'src/client',
});

openapi-ts.config.cjs

/** @type {import('@hey-api/openapi-ts').UserConfig} */
module.exports = {
  input: 'https://get.heyapi.dev/hey-api/backend',
  output: 'src/client',
};

openapi-ts.config.mjs

/** @type {import('@hey-api/openapi-ts').UserConfig} */
export default {
  input: 'https://get.heyapi.dev/hey-api/backend',
  output: 'src/client',
};

Alternatively, you can use openapi-ts.config.js and configure the export statement depending on your project setup.

Input

You must set the input so we can load your OpenAPI specification. It can be a path or URL, object containing a path or URL, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.

If you use an HTTPS URL with a self-signed certificate in development, you will need to set NODE_TLS_REJECT_UNAUTHORIZED=0 in your environment.

Output

You must set the output so we know where to generate your files. It can be a path to the destination folder or an object containing the destination folder path and optional settings.

You should treat the output folder as a dependency. Do not directly modify its contents as your changes might be erased when you run @hey-api/openapi-ts again.

Parser

We parse your input before making it available to plugins. While configuring the parser is optional, it's the perfect place to modify or validate your input if needed.

Plugins

Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces and SDK from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!

Client

Clients are responsible for sending the actual HTTP requests. Using clients is not required, but you must add a client to plugins if you're generating SDKs (we default to Fetch).

Native Clients

Don't see your client? Build your own or let us know your interest by opening an issue.

Native Plugins

These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on GitHub if you'd like us to support your favorite package.

Planned Plugins

The following plugins are planned but not in development yet. You can help us prioritize them by voting on GitHub.

Don't see your plugin? Build your own or let us know your interest by opening an issue.

Migrating

You can learn more on the Migrating page.

License

Released under the MIT License.