-
开发的时候,一般为了测试我们会用postman进行调试,不过今天我介绍一下swagger的用法
安装swaggernpm install @nestjs/swagger swagger-ui-express
-
在main.ts进行调用
import { NestExpressApplication } from '@nestjs/platform-express'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; async function bootstrap() { const app = await NestFactory.create<NestExpressApplication>(AppModule); const config = new DocumentBuilder() .setTitle('Cats example') .setDescription('The cats API description') .setVersion('1.0') .addTag('cats') .build(); const document = SwaggerModule.createDocument(app, config); // 下面的地址‘api‘,自己可以自行修改 SwaggerModule.setup('api', app, document); await app.listen(3000); } bootstrap();
-
打开地址就可以了
http://localhost:3000/api
nestjs 集成Swagger
于 2024-04-26 10:58:49 首次发布