Supported Versions
tsoa supports three major OpenAPI versions:- OpenAPI 3.1 (Latest) - Released 2021, JSON Schema compatible
- OpenAPI 3.0 - Released 2017, widely adopted
- OpenAPI 2.0 (Swagger) - Original specification, deprecated but still supported
Configuring Spec Version
Set the OpenAPI version in yourtsoa.json:
- OpenAPI 3.1
- OpenAPI 3.0
- Swagger 2.0
tsoa.json
Version Comparison
OpenAPI 3.1 vs 3.0
Key Differences
| Feature | OpenAPI 3.1 | OpenAPI 3.0 | Swagger 2.0 |
|---|---|---|---|
| JSON Schema | Full compatibility | Partial | Extended subset |
| Nullable | type: [string, "null"] | nullable: true | x-nullable: true |
| Examples | examples | example | example |
| Webhooks | ✅ Supported | ❌ Not supported | ❌ Not supported |
const | ✅ Supported | ❌ Not supported | ❌ Not supported |
$schema | ✅ Allowed | ❌ Not allowed | ❌ Not allowed |
OpenAPI 3.1 Features
Full JSON Schema Support
OpenAPI 3.1 is fully compatible with JSON Schema 2020-12:Nullable Types
In OpenAPI 3.1, use union types for nullable:Const Values
OpenAPI 3.0 Features
Request Bodies
Explicit request body objects:Multiple Response Types
Security Schemes
tsoa.json
Swagger 2.0 Support
While deprecated, Swagger 2.0 is still supported for legacy systems:tsoa.json
Swagger 2.0 Limitations
Migrating Between Versions
From 2.0 to 3.0
From 3.0 to 3.1
Spec Customization
Basic Information
tsoa.json
Servers
Define multiple server environments:tsoa.json
Tags
Organize endpoints by tags:tsoa.json
External Documentation
tsoa.json
Output Formats
Generate both JSON and YAML:tsoa.json
build/swagger.jsonbuild/swagger.yaml
Viewing Specifications
Swagger UI
Serve your spec with Swagger UI:http://localhost:3000/api-docs
Redoc
Use Redoc for a cleaner documentation UI:Client Generation
Use your OpenAPI spec to generate clients:OpenAPI Generator
Swagger Codegen
Best Practices
Use Latest Stable Version
Use Latest Stable Version
Use OpenAPI 3.0 or 3.1 for new projects. Only use Swagger 2.0 if required for legacy tooling.
Version Your API
Version Your API
Include version in URL or headers, and maintain separate specs for each major version.
Document Everything
Document Everything
Use JSDoc comments for descriptions, examples, and constraints.
Validate Specifications
Validate Specifications
Use tools like Spectral or swagger-cli to validate your spec:
Version Control Specs
Version Control Specs
Commit generated specs to track API changes over time.
Troubleshooting
Spec Generation Fails
- Check TypeScript compilation
- Verify tsoa configuration
- Check for syntax errors in decorators
Invalid Spec
Validate your spec:Missing Types
Ensure all referenced types are exported:Next Steps
Custom Templates
Customize route generation templates
API Documentation
Learn about API documentation