Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Swagger GUI page #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions e2e/Conduit.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"{{USERNAME}}\"}}"
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"{{USERNAME}}\"}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert those changes, this needs to stay the same, its official specs of the https://github.com/gothinkster/realworld project (https://github.com/gothinkster/realworld/blob/main/api/Conduit.postman_collection.json)

},
"url": {
"raw": "{{APIURL}}/users",
Expand Down Expand Up @@ -101,7 +101,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}}"
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}"
},
"url": {
"raw": "{{APIURL}}/users/login",
Expand Down Expand Up @@ -161,7 +161,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"user\":{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}}"
"raw": "{\"email\":\"{{EMAIL}}\", \"password\":\"{{PASSWORD}}\"}"
},
"url": {
"raw": "{{APIURL}}/users/login",
Expand Down Expand Up @@ -662,7 +662,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"article\":{\"title\":\"How to train your dragon\", \"description\":\"Ever wonder how?\", \"body\":\"Very carefully.\", \"tagList\":[\"dragons\",\"training\"]}}"
"raw": "{\"title\":\"How to train your dragon\", \"description\":\"Ever wonder how?\", \"body\":\"Very carefully.\", \"tagList\":[\"dragons\",\"training\"]}"
},
"url": {
"raw": "{{APIURL}}/articles",
Expand Down Expand Up @@ -1641,7 +1641,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"comment\":{\"body\":\"Thank you so much!\"}}"
"raw": "{\"body\":\"Thank you so much!\"}"
},
"url": {
"raw": "{{APIURL}}/articles/{{slug}}/comments",
Expand Down Expand Up @@ -1864,7 +1864,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"user\":{\"email\":\"celeb_{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"celeb_{{USERNAME}}\"}}"
"raw": "{\"email\":\"celeb_{{EMAIL}}\", \"password\":\"{{PASSWORD}}\", \"username\":\"celeb_{{USERNAME}}\"}"
},
"url": {
"raw": "{{APIURL}}/users",
Expand Down
29 changes: 7 additions & 22 deletions e2e/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
"operationId": "CreateArticle",
"parameters": [
{
"name": "article",
"name": "body",
"in": "body",
"required": true,
"description": "Article to create",
Expand Down Expand Up @@ -848,13 +848,8 @@
"NewUserRequest": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/NewUser"
}
},
"required": [
"user"
]
"$ref": "#/definitions/NewUser"
}
},
"User": {
"type": "object",
Expand Down Expand Up @@ -886,13 +881,8 @@
"UserResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/User"
}
},
"required": [
"user"
]
"$ref": "#/definitions/User"
}
},
"UpdateUser": {
"type": "object",
Expand Down Expand Up @@ -1068,13 +1058,8 @@
"NewArticleRequest": {
"type": "object",
"properties": {
"article": {
"$ref": "#/definitions/NewArticle"
}
},
"required": [
"article"
]
"$ref": "#/definitions/NewArticle"
}
},
"UpdateArticle": {
"type": "object",
Expand Down
11 changes: 7 additions & 4 deletions src/article/article.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { User } from '../user/user.decorator';
import { IArticleRO, IArticlesRO, ICommentsRO } from './article.interface';
import { ArticleService } from './article.service';
Expand Down Expand Up @@ -38,18 +38,20 @@ export class ArticleController {
}

@ApiOperation({ summary: 'Create article' })
@ApiBody({ type: CreateArticleDto })
@ApiResponse({ status: 201, description: 'The article has been successfully created.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Post()
async create(@User('id') userId: number, @Body('article') articleData: CreateArticleDto) {
async create(@User('id') userId: number, @Body() articleData: CreateArticleDto) {
return this.articleService.create(userId, articleData);
}

@ApiOperation({ summary: 'Update article' })
@ApiBody({ type: CreateArticleDto })
@ApiResponse({ status: 201, description: 'The article has been successfully updated.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Put(':slug')
async update(@User('id') user: number, @Param() params, @Body('article') articleData: CreateArticleDto) {
async update(@User('id') user: number, @Param() params, @Body() articleData: CreateArticleDto) {
// Todo: update slug also when title gets changed
return this.articleService.update(+user, params.slug, articleData);
}
Expand All @@ -63,10 +65,11 @@ export class ArticleController {
}

@ApiOperation({ summary: 'Create comment' })
@ApiBody({ type: CreateCommentDto })
@ApiResponse({ status: 201, description: 'The comment has been successfully created.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Post(':slug/comments')
async createComment(@User('id') user: number, @Param('slug') slug, @Body('comment') commentData: CreateCommentDto) {
async createComment(@User('id') user: number, @Param('slug') slug, @Body() commentData: CreateCommentDto) {
return this.articleService.addComment(user, slug, commentData);
}

Expand Down
6 changes: 6 additions & 0 deletions src/article/dto/create-article.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateArticleDto {
@ApiProperty()
readonly title!: string;
@ApiProperty()
readonly description!: string;
@ApiProperty()
readonly body!: string;
@ApiProperty()
readonly tagList!: string[];
}
3 changes: 3 additions & 0 deletions src/article/dto/create-comment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateCommentDto {
@ApiProperty()
readonly body!: string;
}
4 changes: 4 additions & 0 deletions src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

export class CreateUserDto {

@IsNotEmpty()
@ApiProperty()
readonly username!: string;

@IsNotEmpty()
@ApiProperty()
readonly email!: string;

@IsNotEmpty()
@ApiProperty()
readonly password!: string;
}
3 changes: 3 additions & 0 deletions src/user/dto/login-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

export class LoginUserDto {

@IsNotEmpty()
@ApiProperty()
readonly email!: string;

@IsNotEmpty()
@ApiProperty()
readonly password!: string;
}
6 changes: 6 additions & 0 deletions src/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';

export class UpdateUserDto {
@ApiProperty()
readonly bio!: string;
@ApiProperty()
readonly email!: string;
@ApiProperty()
readonly image!: string;
@ApiProperty()
readonly username!: string;
}
9 changes: 7 additions & 2 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { UserService } from './user.service';

import {
ApiBearerAuth,
ApiBody,
ApiTags,
getSchemaPath
} from '@nestjs/swagger';

@ApiBearerAuth()
Expand All @@ -28,8 +30,9 @@ export class UserController {
}

@UsePipes(new ValidationPipe())
@ApiBody({ type: CreateUserDto })
@Post('users')
async create(@Body('user') userData: CreateUserDto) {
async create(@Body() userData: CreateUserDto) {
return this.userService.create(userData);
}

Expand All @@ -39,8 +42,9 @@ export class UserController {
}

@UsePipes(new ValidationPipe())
@ApiBody({ type: LoginUserDto })
@Post('users/login')
async login(@Body('user') loginUserDto: LoginUserDto): Promise<IUserRO> {
async login(@Body() loginUserDto: LoginUserDto): Promise<IUserRO> {
const foundUser = await this.userService.findOne(loginUserDto);

const errors = { User: ' not found' };
Expand All @@ -53,3 +57,4 @@ export class UserController {
return { user };
}
}