Generate typescript services and models from Swagger
- Node.js 22+
- PNPM 10+
pnpm add -D swagger-to-tsswagger-to-ts --docUrl https://swagger/v2/api-docs --baseUrl /api --paths /pets,/users --outputDir ./distOr use a JSON/JSONC config file:
swagger-to-ts --configPath ./.vscode/codegen.json{
"docUrl": "https://swagger/v2/api-docs",
"docVersion": "2.0",
"baseName": "",
"baseUrl": "/api",
"templateDir": "",
"outputDir": "./dist",
"paths": [],
"excludePaths": [],
"tagIndex": 0,
"apiCut": [],
"pathReplace": []
}| Option | Description |
|---|---|
-c, --configPath |
JSON/JSONC config file path, for example ./.vscode/codegen.json |
-d, --docUrl |
Swagger or OpenAPI document URL/file path |
-n, --baseName |
Service name prefix |
-b, --baseUrl |
Request path prefix |
-t, --templateDir |
Custom template directory |
-o, --outputDir |
Output directory |
-p, --paths |
Included API paths, comma separated |
-e, --excludePaths |
Excluded API paths, comma separated |
--tagIndex |
Path segment index used as API tag |
--apiCut |
Path segment indexes ignored in generated operation names, comma separated |
--pathReplace |
Request path replacement pair, comma separated |
pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm buildPublishing is handled by GitHub Actions with npm Trusted Publisher. Push a version tag like v1.5.0, or run the Publish workflow manually with a tag input. The workflow publishes to npm first, then creates the GitHub Release after npm publish succeeds.