npm install --save @nestjs/swagger swagger-ui-express
Plain Text
복사
const config = new DocumentBuilder()
.setTitle('Sleact API')
.setDescription('Sleact 를 위한 API 문서입니다.')
.setVersion('1.0')
.addCookieAuth('connect.sid')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
Plain Text
복사
•
Reponse 부분
export class UserDto extends JoinRequestDto {
@ApiProperty( {
required: true,
example: 1,
description: '아이디',
})
id:number;
}
...
@ApiOperation({summary: '회원가입'})
@Post()
postUsers(@Body() data: JoinRequestDto) {
return (this.usersService.postUser(data));
}
@ApiResponse({
status: 200,
description: '성공',
type: UserDto,
})
@ApiResponse({
status: 500,
description: 'Server Error',
})
@ApiOperation({summary: '로그인'})
Plain Text
복사
Controller 위에 @ApiTags
@ApiTags('USERS')
Plain Text
복사
라우트 메소드 위에 @ApiOperation (요악)
@ApiOperation({summary: '내 정보 조회'})
@Get()
getUsers(@Req() req) {
return req.user;
}
Plain Text
복사
ApiParam & ApiQuery
@ApiParam( {
name: 'url',
required: true,
description: '워크스페이스 url',
})
@ApiParam( {
name: 'id',
required: true,
description: 'user id',
})
@ApiQuery( {
name: 'perPage',
required: true,
description: '한번에 가져오는 개수',
})
@ApiQuery( {
name: 'page',
required: true,
description: '불러올 페이지',
})
Plain Text
복사