Home

Awesome

typed-openapi

Generate a Typescript API client from an OpenAPI spec

See the online playground

Screenshot 2023-08-08 at 00 48 42

Features

The generated client is a single file that can be used in the browser or in node. Runtime validation schemas are provided by the excellent typebox-codegen

Install & usage

pnpm add typed-openapi

It exports a bunch of functions that can be used to build your own tooling on top of it. You can look at the CLI code so see how to use them.

CLI

npx typed-openapi -h
typed-openapi/0.1.3

Usage: $ typed-openapi <input>

Commands: <input> Generate

For more info, run any command with the `--help` flag: $ typed-openapi --help

Options: -o, --output <path> Output path for the api client ts file (defaults to `<input>.<runtime>.ts`) -r, --runtime
<name> Runtime to use for validation; defaults to `none`; available: 'none' | 'arktype' | 'io-ts' | 'typebox' |
'valibot' | 'yup' | 'zod' (default: none) -h, --help Display this message -v, --version Display version number

Non-goals

Basically, let's focus on having a fast and typesafe API client generation instead.

Alternatives

openapi-zod-client, which generates a zodios client but can be slow to provide IDE suggestions when the OpenAPI spec is large. Also, you might not always want to use zod or even runtime validation, hence this project.

Contributing

When you're done with your changes, please run pnpm changeset in the root of the repo and follow the instructions described here.