Skip to content

Commit 2d6fedb

Browse files
committed
Fixed Swagger GUI page
1 parent 3691b28 commit 2d6fedb

9 files changed

+49
-34
lines changed

e2e/Conduit.postman_collection.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
],
5050
"body": {
5151
"mode": "raw",
52-
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"{{USERNAME}}\"}}"
52+
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"{{USERNAME}}\"}"
5353
},
5454
"url": {
5555
"raw": "{{APIURL}}/users",
@@ -101,7 +101,7 @@
101101
],
102102
"body": {
103103
"mode": "raw",
104-
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}}"
104+
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}"
105105
},
106106
"url": {
107107
"raw": "{{APIURL}}/users/login",
@@ -161,7 +161,7 @@
161161
],
162162
"body": {
163163
"mode": "raw",
164-
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}}"
164+
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}"
165165
},
166166
"url": {
167167
"raw": "{{APIURL}}/users/login",
@@ -662,7 +662,7 @@
662662
],
663663
"body": {
664664
"mode": "raw",
665-
"raw": "{\"article\":{\"title\":\"How to train your dragon\", \"description\":\"Ever wonder how?\", \"body\":\"Very carefully.\", \"tagList\":[\"dragons\",\"training\"]}}"
665+
"raw": "{\"title\":\"How to train your dragon\", \"description\":\"Ever wonder how?\", \"body\":\"Very carefully.\", \"tagList\":[\"dragons\",\"training\"]}"
666666
},
667667
"url": {
668668
"raw": "{{APIURL}}/articles",
@@ -1641,7 +1641,7 @@
16411641
],
16421642
"body": {
16431643
"mode": "raw",
1644-
"raw": "{\"comment\":{\"body\":\"Thank you so much!\"}}"
1644+
"raw": "{\"body\":\"Thank you so much!\"}"
16451645
},
16461646
"url": {
16471647
"raw": "{{APIURL}}/articles/{{slug}}/comments",
@@ -1864,7 +1864,7 @@
18641864
],
18651865
"body": {
18661866
"mode": "raw",
1867-
"raw": "{\"user\":{\"email\":\"celeb_{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"celeb_{{USERNAME}}\"}}"
1867+
"raw": "{\"email\":\"celeb_{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"celeb_{{USERNAME}}\"}"
18681868
},
18691869
"url": {
18701870
"raw": "{{APIURL}}/users",

e2e/swagger.json

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
"operationId": "CreateArticle",
423423
"parameters": [
424424
{
425-
"name": "article",
425+
"name": "body",
426426
"in": "body",
427427
"required": true,
428428
"description": "Article to create",
@@ -848,13 +848,8 @@
848848
"NewUserRequest": {
849849
"type": "object",
850850
"properties": {
851-
"user": {
852-
"$ref": "#/definitions/NewUser"
853-
}
854-
},
855-
"required": [
856-
"user"
857-
]
851+
"$ref": "#/definitions/NewUser"
852+
}
858853
},
859854
"User": {
860855
"type": "object",
@@ -886,13 +881,8 @@
886881
"UserResponse": {
887882
"type": "object",
888883
"properties": {
889-
"user": {
890-
"$ref": "#/definitions/User"
891-
}
892-
},
893-
"required": [
894-
"user"
895-
]
884+
"$ref": "#/definitions/User"
885+
}
896886
},
897887
"UpdateUser": {
898888
"type": "object",
@@ -1068,13 +1058,8 @@
10681058
"NewArticleRequest": {
10691059
"type": "object",
10701060
"properties": {
1071-
"article": {
1072-
"$ref": "#/definitions/NewArticle"
1073-
}
1074-
},
1075-
"required": [
1076-
"article"
1077-
]
1061+
"$ref": "#/definitions/NewArticle"
1062+
}
10781063
},
10791064
"UpdateArticle": {
10801065
"type": "object",

src/article/article.controller.ts

Lines changed: 7 additions & 4 deletions
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,18 +38,20 @@ 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()
44-
async create(@User('id') userId: number, @Body('article') articleData: CreateArticleDto) {
45+
async create(@User('id') userId: number, @Body() articleData: CreateArticleDto) {
4546
return this.articleService.create(userId, articleData);
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')
52-
async update(@User('id') user: number, @Param() params, @Body('article') articleData: CreateArticleDto) {
54+
async update(@User('id') user: number, @Param() params, @Body() articleData: CreateArticleDto) {
5355
// Todo: update slug also when title gets changed
5456
return this.articleService.update(+user, params.slug, articleData);
5557
}
@@ -63,10 +65,11 @@ 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')
69-
async createComment(@User('id') user: number, @Param('slug') slug, @Body('comment') commentData: CreateCommentDto) {
72+
async createComment(@User('id') user: number, @Param('slug') slug, @Body() commentData: CreateCommentDto) {
7073
return this.articleService.addComment(user, slug, commentData);
7174
}
7275

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { UserService } from './user.service';
77

88
import {
99
ApiBearerAuth,
10+
ApiBody,
1011
ApiTags,
12+
getSchemaPath
1113
} from '@nestjs/swagger';
1214

1315
@ApiBearerAuth()
@@ -28,8 +30,9 @@ export class UserController {
2830
}
2931

3032
@UsePipes(new ValidationPipe())
33+
@ApiBody({ type: CreateUserDto })
3134
@Post('users')
32-
async create(@Body('user') userData: CreateUserDto) {
35+
async create(@Body() userData: CreateUserDto) {
3336
return this.userService.create(userData);
3437
}
3538

@@ -39,8 +42,9 @@ export class UserController {
3942
}
4043

4144
@UsePipes(new ValidationPipe())
45+
@ApiBody({ type: LoginUserDto })
4246
@Post('users/login')
43-
async login(@Body('user') loginUserDto: LoginUserDto): Promise<IUserRO> {
47+
async login(@Body() loginUserDto: LoginUserDto): Promise<IUserRO> {
4448
const foundUser = await this.userService.findOne(loginUserDto);
4549

4650
const errors = { User: ' not found' };
@@ -53,3 +57,4 @@ export class UserController {
5357
return { user };
5458
}
5559
}
60+

0 commit comments

Comments
 (0)