{"id":49210,"library":"rest2ts","title":"rest2ts","description":"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.","status":"active","version":"6.3.5","language":"javascript","source_language":"en","source_url":"git://github.com/gaboe/rest2ts","tags":["javascript","rest","api","typescript","swagger","openapi","client","code-generation","codegen"],"install":[{"cmd":"npm install rest2ts","lang":"bash","label":"npm"},{"cmd":"yarn add rest2ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add rest2ts","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"CLI argument parsing","package":"commander","optional":false},{"reason":"TypeScript types for OpenAPI spec objects","package":"openapi-types","optional":false},{"reason":"Code formatting for generated output","package":"prettier","optional":true}],"imports":[{"note":"ESM-only since v6.1; use named export.","wrong":"const generateTypes = require('rest2ts').generateTypes","symbol":"generateTypes","correct":"import { generateTypes } from 'rest2ts'"},{"note":"Named export, not default. Added in v5.","wrong":"import generateClient from 'rest2ts'","symbol":"generateClient","correct":"import { generateClient } from 'rest2ts'"},{"note":"Type only; use import type if you want elision.","wrong":"interface Rest2tsConfig { ... }","symbol":"Rest2tsConfig","correct":"import { Rest2tsConfig } from 'rest2ts'"}],"quickstart":{"code":"import { generateTypes } from 'rest2ts';\nimport { writeFileSync } from 'fs';\n\nconst config = {\n  spec: 'https://petstore.swagger.io/v2/swagger.json',\n  output: './types',\n  client: 'fetch', // or 'axios', 'ky'\n  prettier: true,\n};\n\nasync function main() {\n  const { files } = await generateTypes(config);\n  for (const file of files) {\n    writeFileSync(file.path, file.content);\n  }\n  console.log(`Generated ${files.length} files`);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates programmatic usage to fetch an OpenAPI spec and generate TypeScript types and a fetch-based client."},"warnings":[{"fix":"Change import from 'rest2ts' to named imports like `import { generateTypes } from 'rest2ts'`","message":"Default export removed in v6.0 in favor of named exports.","severity":"breaking","affected_versions":">=6.0"},{"fix":"Convert your YAML spec to JSON before passing it to rest2ts.","message":"Spec URL must be a valid JSON document; YAML support was experimental and is removed in v6.0.","severity":"deprecated","affected_versions":">=6.0"},{"fix":"Always quote the URL/ path: `npx rest2ts -s 'https://example.com/openapi.json'`","message":"The CLI uses `-s` for spec URL; `-f` for spec file is ambiguous in some shells.","severity":"gotcha","affected_versions":">=5.0"},{"fix":"Use the `--maxDepth` option to limit recursion depth, or manually edit generated types.","message":"Generated files may contain circular references if your OpenAPI spec has recursive schemas. These will compile only with `--strictNullChecks` off.","severity":"gotcha","affected_versions":">=4.0"},{"fix":"Upgrade Node.js to 16 or later.","message":"Node.js 16+ required; v6 dropped support for Node 14.","severity":"breaking","affected_versions":">=6.0"},{"fix":"Switch to `fetch`, `axios`, or `ky`.","message":"The `--client` option value `superagent` is deprecated and will be removed in v7.","severity":"deprecated","affected_versions":">=6.2"}],"env_vars":null,"search_vec":"'2':23 'altern':63 'api':20,82 'boilerpl':75 'cli':3 'client':17,51,86 'code':88 'code-gener':87 'codegen':62,90 'configur':50 'current':27 'depend':43 'differenti':32 'e.g':64 'fetch/axios/ky':54 'file':72 'full':47 'generat':8,52,67,89 'heavier':78 'http':16 'includ':56 'increment':61 'javascript':80 'key':31 'larger':70 'librari':6 'mode':59 'modern':9 'often':68 'openapi':37,66,85 'openapi-gener':65 'output':45,71 'produc':40,69 'releas':29 'requir':77 'rest':19,81 'rest2ts':1 'runtim':79 'safeti':49 'schema':21 'spec':38 'stabl':28 'strong':14 'strongly-typ':13 'support':33 'swagger':35,84 'swagger/openapi':22 'tool':4 'type':11,15,48 'typescript':10,44,83 'v6.3.5':25 'version':39 'watch':58 'week':30 'x/3.x':24 'zero':42 'zero-depend':41","created_at":"2026-06-07T17:00:37.063597+00:00","updated_at":"2026-06-07T17:00:37.063597+00:00","problems":[{"fix":"Install the package: `npm install rest2ts` and use ESM import syntax.","cause":"ESM-only package referenced via require() or not installed.","error":"Error: Cannot find module 'rest2ts'"},{"fix":"Convert spec to valid JSON. rest2ts does not accept YAML since v6.","cause":"Spec file is YAML or malformed JSON.","error":"SyntaxError: Invalid or unexpected token when parsing spec"},{"fix":"Use named import: `import { generateTypes } from 'rest2ts'`.","cause":"Attempted default import in v6+.","error":"TypeError: generateTypes is not a function"},{"fix":"Create the output directory first with `mkdir -p ./types` or use the `--mkdir` flag.","cause":"Output directory does not exist.","error":"Error: No such file or directory: './types'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/gaboe/rest2ts#readme","github":"git://github.com/gaboe/rest2ts","docs":null,"changelog":null,"pypi":null,"npm":"rest2ts","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}