토이프로젝트를 진행중 백엔드 API문서를 작성할 필요성이 생겼다.
npm i @nestjs/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('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, documentFactory);
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
import { ApiProperty } from '@nestjs/swagger';
export class SignInDto {
@ApiProperty({
description: 'user Id',
minLength: 5,
maxLength: 20,
default: '',
})
username: string;
@ApiProperty({
description: 'user password',
minLength: 5,
maxLength: 20,
default: '',
})
password: string;
}
npm run start