Skip to content

Commit

Permalink
feat : swagger 문서 작성을 위한 api decorator 추가 #35
Browse files Browse the repository at this point in the history
- dto에 @ApiProperty 추가
- controller에 @ApiOperation, @ApiResponse 추가

Co-authored-by: GeunH <[email protected]>
  • Loading branch information
LeeTH916 and GeunH committed Nov 15, 2023
1 parent ef1c0a9 commit 77982fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions be/src/user/dto/userInfo.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from "@nestjs/swagger";
import {
IsBoolean,
IsString,
Expand All @@ -8,30 +9,42 @@ import {
} from "class-validator";

export class UserInfoDto {
@ApiProperty({
example: "[email protected]",
description: "The email of the user",
})
@IsEmail()
@IsNotEmpty()
@MaxLength(50)
email: string;

@ApiProperty({ example: "1234", description: "The password of the user" })
@IsString()
@IsNotEmpty()
@MaxLength(50)
password: string;

@ApiProperty({ example: "naver", description: "The provider of the user" })
@IsString()
@IsNotEmpty()
@MaxLength(20)
provider: string;

@ApiProperty({ example: "test", description: "The nickname of the user" })
@IsString()
@IsNotEmpty()
@MaxLength(20)
nickName: string;

@ApiProperty({ example: 20, description: "The age of the user" })
@IsInt()
@IsNotEmpty()
age: number;

@ApiProperty({
example: true,
description: "The gender of the user. true is male, false is female",
})
@IsBoolean()
@IsNotEmpty()
gender: boolean;
Expand Down
4 changes: 4 additions & 0 deletions be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UsePipes,
ValidationPipe,
} from "@nestjs/common";
import { ApiBody, ApiOperation, ApiResponse } from "@nestjs/swagger";
import { UserInfoDto } from "./dto/userInfo.dto";
import { UserService } from "./user.service";

Expand All @@ -14,6 +15,9 @@ export class UserController {
constructor(private userService: UserService) {}

@Post()
@ApiOperation({ summary: "유저 회원가입" })
@ApiResponse({ status: 200, description: "회원가입 성공", type: UserInfoDto })
@ApiResponse({ status: 400, description: "부적절한 요청" })
@UsePipes(new ValidationPipe())
singup(@Body() userInfoDto: UserInfoDto) {
try {
Expand Down

0 comments on commit 77982fe

Please sign in to comment.