Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generate a headless Typescript API client from an OpenAPI spec

NotificationsYou must be signed in to change notification settings

largeTarget/typed-openapi

 
 

Repository files navigation

Generate a Typescript API client from an OpenAPI spec

Seethe online playground

Screenshot 2023-08-08 at 00 48 42

Features

  • Headless API client, bring your own fetcher ! (fetch, axios, ky, etc...)
  • Generates a fully typesafe API client with just types by default (instant suggestions)
  • Or you can also generate a client with runtime validation using one of the following runtimes:

The generated client is a single file that can be used in the browser or in node. Runtime validation schemas areprovided by the excellenttypebox-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 theCLI code so see how to use them.

CLI

npx typed-openapi -h
typed-openapi/0.1.3Usage: $ typed-openapi<input>Commands:<input> GenerateFor more info, run anycommand with the`--help` flag: $ typed-openapi --helpOptions: -o, --output<path> Output pathfor the api client ts file (defaults to`<input>.<runtime>.ts`) -r, --runtime<name> Runtime to usefor 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

  • Caring too much about the runtime validation code. If that works (thanks totypebox-codegen), that's great, otherwise I'm not really interestedin fixing it. If you are, feel free to open a PR.

  • Supporting all the OpenAPI spec. Regex, dates, files, whatever, that's not the point here.openapi-zod-client does a great job at that, but it's slow togenerate the client and the suggestions in the IDE are not instant. I'm only interested in supporting the subset ofthe spec that makes the API client typesafe and fast to provide suggetions in the IDE.

  • Splitting the generated client into multiple files. Nope. Been there, done that. Let's keep it simple.

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

Alternatives

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

Contributing

  • pnpm i
  • pnpm build
  • pnpm test

When you're done with your changes, please runpnpm changeset in the root of the repo and follow the instructionsdescribedhere.

About

Generate a headless Typescript API client from an OpenAPI spec

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript99.9%
  • Other0.1%

[8]ページ先頭

©2009-2025 Movatter.jp