기본환경 구축
$ npm i -g @nestjs/cli
$ nest new [name]
$ npm install --save @nestjs/swagger swagger-ui-express
$ npm install --save @nestjs/swagger swagger-fastify-swagger
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('User example')
.setDescription('The user API description')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api-doc', app, document);
await app.listen(3000);
}
bootstrap();
서버실행
$ npm run start:dev
- 실행화면(localhost:3000/api-doc)

데코레이터 추가
import { IsString, IsNumber } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
export class CreateUserDto {
@ApiProperty({ description: "이름" })
@IsString()
name: string;
@ApiProperty({ description: "나이" })
@IsNumber()
age: number;
}