NestJs学习系列之使用Swagger自动生成接口文档

1. 安装依赖

npm install --save @nestjs/swagger swagger-ui-express

2. 主入口配置Swagge

main.ts
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { ApiUseTags,ApiOperation } from '@nestjs/swagger';

@Controller()
@ApiUseTags('默认')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  @ApiOperation({title:'首页'})
  getHello(): string {
    return this.appService.getHello();
  }
}

3. 效果

4. 坑

有可能因为版本,而导致引入Swagge报错

解决办法:const app = await NestFactory.create(AppModule)

5. 参考

  1. https://docs.nestjs.com/recip...
  2. https://www.bilibili.com/vide...

你可能感兴趣的:(node.js)