Skip to content

Nest.js Swagger 사용법

ez edited this page Nov 12, 2024 · 3 revisions

Nest.js 설치 및 설정

@nestjs/swagger를 설치합니다.

yarn add @nestjs/swagger

main.ts에 swagger를 적용합니다.

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

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

  const config = new DocumentBuilder()
    .setTitle('OctoDocs')
    .setDescription('OctoDocs API 명세서')
    .build();
  const documentFactory = () => SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, documentFactory);
  await app.listen(3000);
}
bootstrap();

@ApiOperation 데코레이터를 사용하면 각 api 별로 설명을 쓸 수 있습니다.

  @ApiOperation({ summary: '페이지를 생성하고 노드도 생성합니다.' })
  @Post('/')
  @HttpCode(HttpStatus.CREATED)
  async createPage(@Body() body: CreatePageDto): Promise<{ message: string }> {
    await this.pageService.createPage(body);
    return {
      message: PageResponseMessage.PAGE_CREATED,
    };
  }

image

개발 문서

⚓️ 사용자 피드백과 버그 기록
👷🏻 기술적 도전
📖 위키와 학습정리
🚧 트러블슈팅

팀 문화

🧸 팀원 소개
⛺️ 그라운드 룰
🍞 커밋 컨벤션
🧈 이슈, PR 컨벤션
🥞 브랜치 전략

그룹 기록

📢 발표 자료
🌤️ 데일리 스크럼
📑 회의록
🏖️ 그룹 회고
🚸 멘토링 일지

Clone this wiki locally