Skip to content

Commit bd57951

Browse files
committed
Fixed Swagger GUI page
1 parent 311a4da commit bd57951

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed

src/article/article.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
2-
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
2+
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
33
import { User } from '../user/user.decorator';
44
import { IArticleRO, IArticlesRO, ICommentsRO } from './article.interface';
55
import { ArticleService } from './article.service';
@@ -38,6 +38,7 @@ export class ArticleController {
3838
}
3939

4040
@ApiOperation({ summary: 'Create article' })
41+
@ApiBody({ type: CreateArticleDto })
4142
@ApiResponse({ status: 201, description: 'The article has been successfully created.' })
4243
@ApiResponse({ status: 403, description: 'Forbidden.' })
4344
@Post()
@@ -46,6 +47,7 @@ export class ArticleController {
4647
}
4748

4849
@ApiOperation({ summary: 'Update article' })
50+
@ApiBody({ type: CreateArticleDto })
4951
@ApiResponse({ status: 201, description: 'The article has been successfully updated.' })
5052
@ApiResponse({ status: 403, description: 'Forbidden.' })
5153
@Put(':slug')
@@ -63,6 +65,7 @@ export class ArticleController {
6365
}
6466

6567
@ApiOperation({ summary: 'Create comment' })
68+
@ApiBody({ type: CreateCommentDto })
6669
@ApiResponse({ status: 201, description: 'The comment has been successfully created.' })
6770
@ApiResponse({ status: 403, description: 'Forbidden.' })
6871
@Post(':slug/comments')

src/article/dto/create-article.dto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
13
export class CreateArticleDto {
4+
@ApiProperty()
25
readonly title!: string;
6+
@ApiProperty()
37
readonly description!: string;
8+
@ApiProperty()
49
readonly body!: string;
10+
@ApiProperty()
511
readonly tagList!: string[];
612
}

src/article/dto/create-comment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
13
export class CreateCommentDto {
4+
@ApiProperty()
25
readonly body!: string;
36
}

src/user/dto/create-user.dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import { ApiProperty } from '@nestjs/swagger';
12
import { IsNotEmpty } from 'class-validator';
23

34
export class CreateUserDto {
45

56
@IsNotEmpty()
7+
@ApiProperty()
68
readonly username!: string;
79

810
@IsNotEmpty()
11+
@ApiProperty()
912
readonly email!: string;
1013

1114
@IsNotEmpty()
15+
@ApiProperty()
1216
readonly password!: string;
1317
}

src/user/dto/login-user.dto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { ApiProperty } from '@nestjs/swagger';
12
import { IsNotEmpty } from 'class-validator';
23

34
export class LoginUserDto {
45

56
@IsNotEmpty()
7+
@ApiProperty()
68
readonly email!: string;
79

810
@IsNotEmpty()
11+
@ApiProperty()
912
readonly password!: string;
1013
}

src/user/dto/update-user.dto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
13
export class UpdateUserDto {
4+
@ApiProperty()
25
readonly bio!: string;
6+
@ApiProperty()
37
readonly email!: string;
8+
@ApiProperty()
49
readonly image!: string;
10+
@ApiProperty()
511
readonly username!: string;
612
}

src/user/user.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { UserService } from './user.service';
77

88
import {
99
ApiBearerAuth,
10+
ApiBody,
1011
ApiTags,
1112
} from '@nestjs/swagger';
1213

@@ -28,6 +29,7 @@ export class UserController {
2829
}
2930

3031
@UsePipes(new ValidationPipe())
32+
@ApiBody({ type: CreateUserDto })
3133
@Post('users')
3234
async create(@Body('user') userData: CreateUserDto) {
3335
return this.userService.create(userData);
@@ -39,8 +41,9 @@ export class UserController {
3941
}
4042

4143
@UsePipes(new ValidationPipe())
44+
@ApiBody({ type: LoginUserDto })
4245
@Post('users/login')
43-
async login(@Body('user') loginUserDto: LoginUserDto): Promise<IUserRO> {
46+
async login(@Body() loginUserDto: LoginUserDto): Promise<IUserRO> {
4447
const foundUser = await this.userService.findOne(loginUserDto);
4548

4649
const errors = { User: ' not found' };

0 commit comments

Comments
 (0)