openapi: 3.0.0 info: title: API Documentation description: API documentation for user-related endpoints version: 1.0.0 servers: - url: http://localhost:3000/api tags: - name: User description: User-related endpoints - name: Auth description: Authenticate && Authorize paths: /users/profile: get: tags: - User summary: Get user profile description: Retrieve the profile of the currently authenticated user. responses: '200': description: Successfully retrieved user profile content: application/json: schema: type: object properties: user: type: object properties: id: type: string description: User ID example: "60d21babd3e7e5f7d7d9b8c3" email: type: string description: User's email address example: "user@example.com" name: type: string description: User's name example: "John Doe" '401': description: Unauthorized - User not authenticated content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /users/me: get: tags: - User summary: Get current user description: Retrieve information about the currently authenticated user. responses: '200': description: Successfully retrieved current user information content: application/json: schema: type: object properties: user: type: object properties: id: type: string description: User ID example: "60d21babd3e7e5f7d7d9b8c3" email: type: string description: User's email address example: "user@example.com" name: type: string description: User's name example: "John Doe" '401': description: Unauthorized - User not authenticated content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /users/change-password: put: tags: - User summary: Change user password description: Change the password for the currently authenticated user. requestBody: required: true content: application/json: schema: type: object properties: oldPassword: type: string description: Current password of the user example: "OldPassword123!" newPassword: type: string description: New password for the user example: "NewPassword456!" required: - oldPassword - newPassword responses: '200': description: Password changed successfully content: application/json: schema: type: object properties: message: type: string description: Success message example: "Password changed successfully" '400': description: Bad request - Invalid input content: application/json: schema: type: object properties: error: type: string description: Error message example: "Old password is incorrect" '401': description: Unauthorized - User not authenticated content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /users/: get: tags: - User summary: Get all users description: Retrieve a list of all users. Restricted to admin users only. responses: '200': description: Successfully retrieved list of users content: application/json: schema: type: array items: type: object properties: id: type: string description: User ID example: "60d21babd3e7e5f7d7d9b8c3" email: type: string description: User's email address example: "user@example.com" name: type: string description: User's name example: "John Doe" '401': description: Unauthorized - User not authenticated or not authorized content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /users/{id}: delete: tags: - User summary: Delete a user description: Delete a user by ID. Restricted to admin users only. parameters: - in: path name: id required: true schema: type: string description: ID of the user to delete responses: '200': description: User deleted successfully content: application/json: schema: type: object properties: message: type: string description: Success message example: "User deleted successfully" '401': description: Unauthorized - User not authenticated or not authorized content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '404': description: Not found - User not found content: application/json: schema: type: object properties: error: type: string description: Error message example: "User not found" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /auth/login: post: tags: - Auth summary: User login description: Authenticate a user and return a JWT token for accessing protected routes. requestBody: required: true content: application/json: schema: type: object properties: email: type: string description: The user's email address example: "user@example.com" password: type: string description: The user's password example: "UserPassword123!" required: - email - password responses: '200': description: Successfully authenticated the user content: application/json: schema: type: object properties: token: type: string description: JWT token to be used for authenticated requests example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." '400': description: Invalid input - missing or incorrect email/password content: application/json: schema: type: object properties: error: type: string description: Error message example: "Invalid email or password" '401': description: Unauthorized - Incorrect email or password content: application/json: schema: type: object properties: error: type: string description: Error message example: "Unauthorized access" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error" /auth/register: post: tags: - Auth summary: User registration description: Register a new user by providing their email and password. requestBody: required: true content: application/json: schema: type: object properties: email: type: string description: The user's email address example: "newuser@example.com" password: type: string description: The user's password example: "NewUserPassword123!" confirmPassword: type: string description: Confirmation of the user's password example: "NewUserPassword123!" required: - email - password - confirmPassword responses: '201': description: User registered successfully content: application/json: schema: type: object properties: message: type: string description: Success message example: "User registered successfully" '400': description: Bad request - Invalid input or passwords do not match content: application/json: schema: type: object properties: error: type: string description: Error message example: "Passwords do not match" '409': description: Conflict - Email already in use content: application/json: schema: type: object properties: error: type: string description: Error message example: "Email already in use" '500': description: Server error content: application/json: schema: type: object properties: error: type: string description: Error message example: "Internal server error"