
API Documentation & Contracts
Swagger, OpenAPI, versioning, documentation per version, Postman, collections, API contracts
1What is Swagger in the context of NestJS?
What is Swagger in the context of NestJS?
回答
Swagger is a tool that automatically generates interactive REST API documentation by analyzing NestJS decorators. This documentation allows you to visualize and test endpoints directly from a web interface accessible via /api. Installing the @nestjs/swagger package and configuring SwaggerModule in main.ts are required to use it.
2Which package should be installed to use Swagger in NestJS?
Which package should be installed to use Swagger in NestJS?
回答
The @nestjs/swagger package is the official library for integrating Swagger into a NestJS application. You also need to install swagger-ui-express which provides the interactive web interface. These two packages work together to generate OpenAPI documentation and display it in the browser.
3Where to configure SwaggerModule in a NestJS application?
Where to configure SwaggerModule in a NestJS application?
回答
SwaggerModule is configured in the main.ts file after creating the NestJS application with NestFactory.create(). The SwaggerModule.setup() method takes three parameters: the documentation path, the application instance, and the document generated by createDocument(). This configuration must be done before app.listen() so the documentation is accessible at startup.
What is the role of the @ApiTags() decorator?
What is OpenAPI?
+17 面接問題