跳至主要内容

🐔 安裝 Swagger

步驟​

安裝​

pnpm install --save @nestjs/swagger

Bootstrap 設定​

import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; //swagger
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

// [B] swagger
const config = new DocumentBuilder()
.setTitle('Car API')
.setDescription('The Car API description')
.setVersion('1.0')
.addTag('Car')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
// [E] swagger
await app.listen(3050);
}
bootstrap();

啟動​

pnpm start

http://localhost:3050/api