- Notifications
You must be signed in to change notification settings - Fork0
Generate a headless Typescript API client from an OpenAPI spec
largeTarget/typed-openapi
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Generate a Typescript API client from an OpenAPI spec
- 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
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.
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
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.
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.
pnpm ipnpm buildpnpm 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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- TypeScript99.9%
- Other0.1%
