Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

@hey-api/openapi-ts

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hey-api/openapi-ts

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

  • 0.61.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
167K
increased by18.59%
Maintainers
1
Weekly downloads
Β 
Created
Source
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

  • 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

Sponsors

Love Hey API? Become our sponsor.

Stainless logo

GitHub Integration (coming 2025)

Automatically update your code when the APIs it depends on change. Find out more.

Quick Start

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

npx @hey-api/openapi-ts \
  -c @hey-api/client-fetch \
  -i path/to/openapi.json \
  -o src/client \

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.

Installation

npm
npm install @hey-api/client-fetch && npm install @hey-api/openapi-ts -D
pnpm
pnpm add @hey-api/client-fetch && pnpm add @hey-api/openapi-ts -D
yarn
yarn add @hey-api/client-fetch && yarn add @hey-api/openapi-ts -D
bun
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

@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({
  client: '@hey-api/client-fetch',
  input: 'path/to/openapi.json',
  output: 'src/client',
});
openapi-ts.config.cjs
/** @type {import('@hey-api/openapi-ts').UserConfig} */
module.exports = {
  client: '@hey-api/client-fetch',
  input: 'path/to/openapi.json',
  output: 'src/client',
};
openapi-ts.config.mjs
/** @type {import('@hey-api/openapi-ts').UserConfig} */
export default {
  client: '@hey-api/client-fetch',
  input: 'path/to/openapi.json',
  output: 'src/client',
};

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

Input

Input is the first thing you must define. It can be a path, URL, or a string content resolving to 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

Output is the next thing to define. It can be either a string pointing to the destination folder or a configuration object containing the destination folder path and optional settings (these are described below).

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.

Client

Clients are responsible for sending the actual HTTP requests. The client value is not required, but you must define it if you're generating SDKs (enabled by default).

You can learn more on the Clients page.

Parser

If you're NOT using a legacy client, we encourage you to try out the experimental parser. Soon, it will become the default parser, but until it's been tested it's an opt-in feature. To try it out, set the experimentalParser flag in your configuration to true.

config
export default {
  client: '@hey-api/client-fetch',
  experimentalParser: true,
  input: 'path/to/openapi.json',
  output: 'src/client',
};
cli
npx @hey-api/openapi-ts \
  -c @hey-api/client-fetch \
  -e \
  -i path/to/openapi.json \
  -o src/client

The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as Filters and more are being added.

The legacy parser will be used with the legacy clients regardless of the experimentalParser flag value. However, it's unlikely to receive any further updates.

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!

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.

Migration Guides

OpenAPI Typescript Codegen

License

Released under the MIT License.

Keywords

FAQs

Package last updated on 08 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc