A CLI tool and library that generates modern TypeScript types and strongly-typed HTTP clients from REST API schemas (Swagger/OpenAPI 2.x/3.x). v6.3.5 is current stable; releases weekly. Key differentiators: supports both Swagger and OpenAPI spec versions, produces zero-dependency TypeScript output with full type safety, configurable client generation for fetch/axios/ky, and includes a watch mode for incremental codegen. Alternatives (e.g., openapi-generator) often produce larger output files with more boilerplate or require heavier runtimes.
npm install rest2tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage to fetch an OpenAPI spec and generate TypeScript types and a fetch-based client.
Change import from 'rest2ts' to named imports like `import { generateTypes } from 'rest2ts'`Convert your YAML spec to JSON before passing it to rest2ts.
Always quote the URL/ path: `npx rest2ts -s 'https://example.com/openapi.json'`
Use the `--maxDepth` option to limit recursion depth, or manually edit generated types.
Upgrade Node.js to 16 or later.
Switch to `fetch`, `axios`, or `ky`.
Install the package: `npm install rest2ts` and use ESM import syntax.
Convert spec to valid JSON. rest2ts does not accept YAML since v6.
Use named import: `import { generateTypes } from 'rest2ts'`.Create the output directory first with `mkdir -p ./types` or use the `--mkdir` flag.