라이브러리, 프레임워크/Swagger

[Swagger + NestJS] 초기 세팅

dv_jamie 2022. 6. 15. 18:36

swagger 설치

npm i @nestjs/swagger swagger-ui-express

 

main.ts

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const options = new DocumentBuilder()
    .setTitle('SNS API') // 제목
    .setDescription('sns api for practice') // 설명
    .setVersion('1.0.0') // 버전 (적지 않으면 1.0.0 으로 올라감)
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api-docs', app, document); // 첫번째 인자: uri

  await app.listen(3000);
}
bootstrap();

 

결과