Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
tsoa is a TypeScript framework for building RESTful APIs. It provides tools to automatically generate OpenAPI documentation and route handlers based on TypeScript interfaces and decorators.
Automatic Route Generation
tsoa allows you to define your API routes using TypeScript decorators. The above code defines a route '/users' that returns a list of users.
import { Controller, Get, Route } from 'tsoa';
@Route('users')
export class UserController extends Controller {
@Get()
public async getUsers(): Promise<User[]> {
return [{ id: 1, name: 'John Doe' }];
}
}
OpenAPI Specification Generation
tsoa can automatically generate OpenAPI specifications and route handlers based on your TypeScript code. This helps in keeping your API documentation up-to-date with your code.
import { generateRoutes, generateSpec } from 'tsoa';
const app = express();
// Generate OpenAPI spec
generateSpec({
entryFile: './src/server.ts',
outputDirectory: './dist',
specVersion: 3
});
// Generate routes
generateRoutes({
entryFile: './src/server.ts',
routesDir: './dist'
});
Request Validation
tsoa provides built-in request validation. The above code demonstrates how to validate query parameters using decorators.
import { Controller, Get, Route, Query } from 'tsoa';
@Route('users')
export class UserController extends Controller {
@Get()
public async getUsers(@Query() age: number): Promise<User[]> {
// Validate the 'age' query parameter
if (age < 0) {
throw new Error('Age must be a positive number');
}
return [{ id: 1, name: 'John Doe', age }];
}
}
express-openapi is a framework for building APIs with Express and OpenAPI. It allows you to define your API using OpenAPI specifications and automatically generates route handlers. Compared to tsoa, express-openapi focuses more on OpenAPI specifications and less on TypeScript integration.
NestJS is a progressive Node.js framework for building efficient, reliable, and scalable server-side applications. It uses TypeScript and provides a lot of built-in features like dependency injection, modular architecture, and more. While tsoa focuses on generating OpenAPI documentation and route handlers, NestJS offers a more comprehensive solution for building server-side applications.
swagger-jsdoc is a library that allows you to integrate JSDoc comments with Swagger (OpenAPI) documentation. It generates OpenAPI documentation based on JSDoc comments in your code. Unlike tsoa, swagger-jsdoc does not provide route generation or TypeScript integration.
Check out the guides
See example controllers in the tests
See example models in the tests
To contribute (via a PR), please first see the Contributing Guide
tsoa wants additional maintainers! The library has increased in popularity and has quite a lot of pull requests and issues. Please post in this issue if you're willing to take on the role of a maintainer.
FAQs
Build swagger-compliant REST APIs using TypeScript and Node
The npm package tsoa receives a total of 168,904 weekly downloads. As such, tsoa popularity was classified as popular.
We found that tsoa demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.