Skip to content

Commit

Permalink
refactor: revise the document according to the OpenAPI specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
a20688392 committed Sep 1, 2023
1 parent a3f71c3 commit 6c7423c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 107 deletions.
12 changes: 6 additions & 6 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
ApiUnauthorizedResponse,
} from "@nestjs/swagger";
import { Request } from "express";
import { BadRequestError } from "src/error/bad-request-error";
import { ConflictError } from "src/error/conflict-error";
import { ForbiddenError } from "src/error/forbidden-error";
import { UnauthorizedError } from "src/error/unauthorized-error";
import { CreateUserDto } from "src/user/dto/create-user.dto";
import { LoginUserDto } from "src/user/dto/login-user.dto";
import { CreateUserBadRequestError } from "src/user/exceptions/create-user-badrequest-error.exception";
import { CreateUserConflictError } from "src/user/exceptions/create-user-conflict-error.exception";
import { CreateUserResponse } from "src/user/responses/create-user-response";

import { AuthService } from "./auth.service";
import { ForbiddenError } from "./exception/ForbiddenError";
import { UnauthorizedError } from "./exception/UnauthorizedError";
import { type JwtUser } from "./jwt/jwt.interface";
import { JwtRefreshGuard } from "./jwt/jwt-refresh.guard";
import { LocalAuthGuard } from "./local/local-auth.guard";
Expand All @@ -41,11 +41,11 @@ export class AuthController {
})
@ApiConflictResponse({
description: "使用者資料重覆",
type: CreateUserConflictError,
type: ConflictError,
})
@ApiBadRequestResponse({
description: "使用者格式不符",
type: CreateUserBadRequestError,
type: BadRequestError,
})
async register(@Body() userDto: CreateUserDto) {
return this.authService.register(userDto);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/responses/generate-token.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class GenerateTokenResponse {

@ApiProperty({
description: "HTTP Code",
example: "201",
example: 201,
type: "number",
})
public readonly statusCode: number;
Expand Down
17 changes: 17 additions & 0 deletions src/error/bad-request-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from "@nestjs/swagger";

export class BadRequestError {
@ApiProperty({
description: "HTTP Code",
example: 400,
type: "number",
})
public readonly statusCode: number;

@ApiProperty({
description: "Error Message",
example: ["Error Message"],
type: "array",
})
public readonly error: string[];
}
17 changes: 17 additions & 0 deletions src/error/conflict-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from "@nestjs/swagger";

export class ConflictError {
@ApiProperty({
description: "HTTP Code",
example: 409,
type: "number",
})
public readonly statusCode: number;

@ApiProperty({
description: "Error Message",
example: ["Error Message"],
type: "array",
})
public readonly error: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ApiProperty } from "@nestjs/swagger";
export class ForbiddenError {
@ApiProperty({
description: "HTTP Code",
example: "403",
example: 403,
type: "number",
})
public readonly statusCode: number;

@ApiProperty({
description: "Error message",
example: "Forbidden",
description: "Error Message",
example: "Error Message",
type: "string",
})
public readonly message: string;
public readonly error: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ApiProperty } from "@nestjs/swagger";
export class UnauthorizedError {
@ApiProperty({
description: "HTTP Code",
example: "401",
example: 401,
type: "number",
})
public readonly statusCode: number;

@ApiProperty({
description: "Error message",
description: "Error Message",
example: "Unauthorized",
type: "string",
})
public readonly message: string;
public readonly error: string;
}
55 changes: 0 additions & 55 deletions src/user/exceptions/create-user-badrequest-error.exception.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/user/exceptions/create-user-conflict-error.exception.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/user/responses/create-user-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ApiProperty } from "@nestjs/swagger";
export class CreateUserResponse {
@ApiProperty({
description: "HTTP 回應代碼",
example: "201",
example: 201,
type: "number",
})
public readonly statusCode: number;

@ApiProperty({
description: "創建成功回應",
example: "創建成功",
type: "number",
type: "string",
})
public readonly message: string;
}

0 comments on commit 6c7423c

Please sign in to comment.