Installation
Install tsoa as a development dependency in your project:Quick Start
Once installed, you can use the tsoa CLI through npm scripts or directly via npx:Core Commands
tsoa provides three primary commands:spec
Generate OpenAPI specification from your TypeScript controllers
routes
Generate Express/Koa/Hapi route handlers with validation
spec-and-routes
Generate both spec and routes in a single pass (faster)
Configuration File
All CLI commands rely on a configuration file (default:tsoa.json) that defines:
- Entry points to your API controllers
- Output directories for generated files
- OpenAPI specification options
- Route generation settings
- Middleware selection (Express, Koa, or Hapi)
Workflow Integration
Development Workflow
For development, regenerate specs and routes when controllers change:Build Pipeline
Integrate tsoa generation into your build process:package.json
CI/CD Integration
Validate that generated files are up-to-date in CI:.github/workflows/ci.yml
Common Flags
All commands support these common options:Path to the tsoa configuration file
Override the base API path from configuration
Display help information for any command
Output Files
Depending on your configuration, tsoa generates:Specification Files
swagger.jsonorswagger.yaml- OpenAPI specification- Location determined by
spec.outputDirectoryandspec.specFileBaseName
Route Files
routes.ts- Generated route handlers with validation- Location determined by
routes.routesDirandroutes.routesFileName - Includes type-safe request/response handling
- Built-in validation middleware
Generated files should typically be committed to version control, as they’re part of your application’s runtime behavior.
Error Handling
The CLI provides detailed error messages for common issues:Missing configuration file
Missing configuration file
tsoa.json file or specify a custom path with --configurationInvalid entry file
Invalid entry file
entryFile path is correct and the file existsMissing output directory
Missing output directory
spec.outputDirectory or routes.routesDir to your configNext Steps
Commands Reference
Detailed documentation for each CLI command
Configuration Guide
Complete configuration options and examples
tsoa.json Schema
Full configuration schema reference
Quick Start
Get started with a complete example