Commit 7cdcb77c authored by ThinhNC's avatar ThinhNC

feat: add Swagger configuration and API documentation schemas for...

feat: add Swagger configuration and API documentation schemas for authentication and user management
parent 31c92557
......@@ -100,8 +100,6 @@ export const swaggerSpec = {
LoginResponse: {
type: 'object',
properties: {
accessToken: { type: 'string' },
refreshToken: { type: 'string' },
user: { $ref: '#/components/schemas/User' },
},
},
......@@ -114,18 +112,63 @@ export const swaggerSpec = {
},
RefreshBody: {
type: 'object',
required: ['refreshToken'],
properties: {
refreshToken: { type: 'string' },
},
},
LogoutBody: {
type: 'object',
required: ['refreshToken'],
properties: {
refreshToken: { type: 'string' },
},
},
RegisterBody: {
type: 'object',
required: ['email', 'password'],
properties: {
email: { type: 'string', format: 'email', example: 'user@gmail.com' },
password: { type: 'string', minLength: 8, example: 'User@123456' },
fullName: { type: 'string', example: 'Nguyen Van A' },
},
},
UpdateProfileBody: {
type: 'object',
properties: {
fullName: { type: 'string', example: 'Nguyen Van B' },
avatarUrl: { type: 'string', format: 'uri', example: 'https://example.com/avatar.jpg' },
phoneNumber: { type: 'string', example: '0912345678' },
},
},
UpdatePasswordBody: {
type: 'object',
required: ['newPassword'],
properties: {
oldPassword: { type: 'string', example: 'OldPassword@123' },
newPassword: { type: 'string', minLength: 8, example: 'NewPassword@123' },
},
},
ForgotPasswordBody: {
type: 'object',
required: ['email'],
properties: {
email: { type: 'string', format: 'email', example: 'user@gmail.com' },
},
},
ResetPasswordBody: {
type: 'object',
required: ['token', 'newPassword'],
properties: {
token: { type: 'string', format: 'uuid', example: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' },
newPassword: { type: 'string', minLength: 8, example: 'NewPassword@123' },
},
},
ResendVerificationBody: {
type: 'object',
required: ['email'],
properties: {
email: { type: 'string', format: 'email', example: 'user@gmail.com' },
},
},
},
parameters: {
PageParam: { in: 'query', name: 'page', schema: { type: 'integer', default: 1 } },
......@@ -168,6 +211,53 @@ export const swaggerSpec = {
},
},
},
'/auth/register': {
post: {
tags: ['Auth'],
summary: 'Đăng ký tài khoản mới (chỉ cho phép gmail.com)',
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/RegisterBody' } } } },
responses: {
201: {
description: 'Đăng ký thành công, vui lòng kiểm tra email để kích hoạt tài khoản',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Verification email sent' } } },
],
},
},
},
},
400: { description: 'Email đã tồn tại hoặc không phải gmail.com', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/verify-email': {
get: {
tags: ['Auth'],
summary: 'Xác thực kích hoạt email',
parameters: [{ in: 'query', name: 'token', required: true, schema: { type: 'string', format: 'uuid' }, description: 'Mã xác thực gửi qua email' }],
responses: {
200: {
description: 'Kích hoạt tài khoản thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Email verified successfully' } } },
],
},
},
},
},
400: { description: 'Token không hợp lệ hoặc đã hết hạn', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } },
},
},
},
'/auth/login': {
post: {
tags: ['Auth'],
......@@ -192,6 +282,129 @@ export const swaggerSpec = {
},
},
},
'/auth/resend-verification': {
post: {
tags: ['Auth'],
summary: 'Gửi lại email xác thực kích hoạt tài khoản',
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/ResendVerificationBody' } } } },
responses: {
200: {
description: 'Gửi lại email xác thực thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Verification email sent successfully' } } },
],
},
},
},
},
400: { description: 'Tài khoản đã được xác thực trước đó', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } },
404: { $ref: '#/components/responses/NotFound' },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/forgot-password': {
post: {
tags: ['Auth'],
summary: 'Yêu cầu đặt lại mật khẩu (quên mật khẩu)',
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/ForgotPasswordBody' } } } },
responses: {
200: {
description: 'Đã gửi link khôi phục mật khẩu qua email',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Password reset link sent to your email' } } },
],
},
},
},
},
404: { $ref: '#/components/responses/NotFound' },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/reset-password': {
post: {
tags: ['Auth'],
summary: 'Đặt lại mật khẩu mới bằng token khôi phục',
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/ResetPasswordBody' } } } },
responses: {
200: {
description: 'Đặt lại mật khẩu mới thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Password has been reset successfully' } } },
],
},
},
},
},
400: { description: 'Token không hợp lệ hoặc đã hết hạn', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/profile': {
put: {
tags: ['Auth'],
summary: 'Cập nhật thông tin cá nhân',
security: [{ BearerAuth: [] }],
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/UpdateProfileBody' } } } },
responses: {
200: {
description: 'Cập nhật thông tin thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Profile updated successfully' } } },
],
},
},
},
},
401: { $ref: '#/components/responses/Unauthorized' },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/password': {
put: {
tags: ['Auth'],
summary: 'Cập nhật mật khẩu',
security: [{ BearerAuth: [] }],
requestBody: { required: true, content: { 'application/json': { schema: { $ref: '#/components/schemas/UpdatePasswordBody' } } } },
responses: {
200: {
description: 'Cập nhật mật khẩu thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'Password updated successfully' } } },
],
},
},
},
},
401: { $ref: '#/components/responses/Unauthorized' },
422: { $ref: '#/components/responses/Validation' },
},
},
},
'/auth/me': {
get: {
tags: ['Auth'],
......@@ -379,6 +592,30 @@ export const swaggerSpec = {
422: { $ref: '#/components/responses/Validation' },
},
},
delete: {
tags: ['Users'],
summary: 'Xóa mềm tài khoản',
security: [{ BearerAuth: [] }],
parameters: [{ in: 'path', name: 'id', required: true, schema: { type: 'string', format: 'uuid' } }],
responses: {
200: {
description: 'Xóa mềm tài khoản thành công',
content: {
'application/json': {
schema: {
allOf: [
{ $ref: '#/components/schemas/SuccessResponse' },
{ type: 'object', properties: { message: { type: 'string', example: 'User soft deleted successfully' } } },
],
},
},
},
},
401: { $ref: '#/components/responses/Unauthorized' },
403: { $ref: '#/components/responses/Forbidden' },
404: { $ref: '#/components/responses/NotFound' },
},
},
},
},
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment