openapi: 3.0.0 info: title: Acamae API version: 2.0.0 description: | API for the Acamae application with consistent response structure. **Response Structure:** - All responses follow the same pattern - Include timestamp and requestId for traceability - Messages in English - Specific semantic codes **Note on Network Errors:** > Errors such as `ERR_NETWORK`, `ERR_CANCELED`, `ECONNABORTED`, and `ETIMEDOUT` are not returned by the backend, but are generated by the client (e.g., Axios) when there is no valid HTTP response from the server (e.g., network failure, timeout, cancellation). In these cases, the status is always `0` and the error is differentiated by the `code` field. These are documented for completeness, but are not part of the backend's HTTP responses. components: schemas: # ===== RESPONSE SCHEMAS ===== ApiSuccessResponse: type: object required: - success - data - status - code - message - timestamp - requestId properties: success: type: boolean example: true description: Indicates if the operation was successful data: description: The response data (can be null, object, array) status: type: number example: 200 description: HTTP status code code: type: string example: 'SUCCESS' description: Application semantic code message: type: string example: 'Operation successful' description: Descriptive message in English timestamp: type: string format: date-time example: '2024-01-15T10:30:00.000Z' description: ISO 8601 timestamp of the response requestId: type: string format: uuid example: '550e8400-e29b-41d4-a716-446655440000' description: Unique request ID for traceability meta: type: object description: Additional metadata (pagination, totals, etc.) ApiErrorResponse: type: object required: - success - data - status - code - message - timestamp - requestId properties: success: type: boolean example: false description: Indicates if the operation was successful data: nullable: true example: null description: Always null in errors status: type: number example: 400 description: HTTP status code code: type: string example: 'AUTH_INVALID_CREDENTIALS' description: Semantic error code message: type: string example: 'The provided credentials are incorrect' description: Error message in English timestamp: type: string format: date-time example: '2024-01-15T10:30:00.000Z' description: ISO 8601 timestamp of the response requestId: type: string format: uuid example: '550e8400-e29b-41d4-a716-446655440000' description: Unique request ID for traceability meta: type: object description: Additional metadata error: type: object description: Specific error details properties: type: type: string enum: [validation, network, server, authentication, authorization, business] example: 'authentication' description: Error type details: type: array description: Field-specific errors items: type: object properties: field: type: string example: 'password' description: Field that caused the error code: type: string example: 'INVALID' description: Field-specific code message: type: string example: 'The password is not valid' description: Specific message in English stack: type: string description: Stack trace (development only) # ===== ENTITIES ===== User: type: object properties: id: type: string example: 'user_123456' email: type: string format: email example: 'user@example.com' username: type: string example: 'user123' role: type: string enum: [user, admin] example: 'user' createdAt: type: string format: date-time example: '2024-01-15T10:30:00.000Z' updatedAt: type: string format: date-time example: '2024-01-15T10:30:00.000Z' UserWithTokens: type: object properties: user: $ref: '#/components/schemas/User' accessToken: type: string example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' refreshToken: type: string example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' # ===== PAYLOADS ===== LoginPayload: type: object required: - email - password properties: email: type: string format: email example: 'user@example.com' password: type: string format: password example: 'Password123!' RegisterPayload: type: object required: - email - password - username properties: email: type: string format: email example: 'user@example.com' password: type: string format: password example: 'Password123!' username: type: string example: 'user123' ForgotPasswordPayload: type: object required: - email properties: email: type: string format: email example: 'user@example.com' ResetPasswordPayload: type: object required: - password properties: password: type: string format: password example: 'NewPassword123!' ValidateResetTokenPayload: type: object required: - token properties: token: type: string example: 'abc123def456...xyz789' description: | Reset token to validate. Hexadecimal token: 64 consecutive hexadecimal characters ResetTokenValidationResponse: type: object properties: isValid: type: boolean example: true description: Whether the token is valid isExpired: type: boolean example: false description: Whether the token has expired userExists: type: boolean example: true description: Whether the associated user exists ResendVerificationPayload: type: object required: - identifier properties: identifier: type: string example: 'user@example.com' description: User email # ===== SECURITY ===== securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: JWT token obtained from login endpoint responses: NetworkError: description: | Network/transport error (client-side, status 0) **Note:** These errors are generated by the client (not the backend) when there is no valid HTTP response. The status is always `0` and the error is identified by the `code` field (e.g., `ERR_NETWORK`, `ECONNABORTED`, etc.). content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: err_network: summary: Network error value: success: false data: null status: 0 code: 'ERR_NETWORK' message: 'Network error. Check your connection' timestamp: '2024-01-15T10:30:00.000Z' requestId: 'req-uuid' error: type: 'network' details: - field: 'network' code: 'ERR_NETWORK' message: 'Request failed' err_canceled: summary: Request canceled value: success: false data: null status: 0 code: 'ERR_CANCELED' message: 'Request was canceled' timestamp: '2024-01-15T10:30:00.000Z' requestId: 'req-uuid' error: type: 'network' details: - field: 'network' code: 'ERR_CANCELED' message: 'Request was canceled' econnaborted: summary: Connection aborted value: success: false data: null status: 0 code: 'ECONNABORTED' message: 'Connection aborted' timestamp: '2024-01-15T10:30:00.000Z' requestId: 'req-uuid' error: type: 'network' details: - field: 'network' code: 'ECONNABORTED' message: 'Connection aborted' etimedout: summary: Timeout value: success: false data: null status: 0 code: 'ETIMEDOUT' message: 'Request timed out' timestamp: '2024-01-15T10:30:00.000Z' requestId: 'req-uuid' error: type: 'network' details: - field: 'network' code: 'ETIMEDOUT' message: 'Request timed out' paths: # ===== AUTHENTICATION ===== /auth/login: post: tags: - Authentication summary: Login description: Authenticate user with email and password requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/LoginPayload' examples: valid_login: summary: Valid login value: email: 'user@example.com' password: 'Password123!' responses: '200': description: Successful login content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/UserWithTokens' examples: login_success: summary: Successful login value: success: true data: user: id: 'user_123456' email: 'user@example.com' username: 'user123' role: 'user' createdAt: '2024-01-15T10:30:00.000Z' updatedAt: '2024-01-15T10:30:00.000Z' accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' status: 200 code: 'SUCCESS' message: 'Login successful' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '401': description: Incorrect password or email not verified content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: invalid_password: summary: Incorrect password value: success: false data: null status: 401 code: 'AUTH_FORBIDDEN' message: 'Invalid password' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'password' code: 'INVALID' message: 'Invalid password' email_not_verified: summary: Email not verified value: success: false data: null status: 401 code: 'EMAIL_NOT_VERIFIED' message: 'Email not verified' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'email' code: 'NOT_VERIFIED' message: 'Email not verified' '404': description: Invalid email (user not found) content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: invalid_email: summary: Invalid email value: success: false data: null status: 404 code: 'AUTH_INVALID_CREDENTIALS' message: 'Invalid credentials' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'email' code: 'INVALID' message: 'Invalid email' '422': description: Invalid input data content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: validation_error: summary: Validation failed value: success: false data: null status: 422 code: 'VALIDATION_ERROR' message: 'The submitted data is not valid' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'validation' details: - field: 'email' code: 'INVALID_FORMAT' message: 'The email format is not valid' - field: 'password' code: 'REQUIRED' message: 'Password is required' '429': description: Too many attempts content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: rate_limit: summary: Rate limit exceeded value: success: false data: null status: 429 code: 'AUTH_RATE_LIMIT' message: 'Too many login attempts. Try again in 15 minutes' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '500': description: Server error content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' unknown_error: summary: Unknown error value: success: false data: null status: 500 code: 'UNKNOWN_ERROR' message: 'Internal server error' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'server' code: 'UNKNOWN_ERROR' message: 'An unexpected error occurred' default: $ref: '#/components/responses/NetworkError' /auth/register: post: tags: - Authentication summary: Register new user description: | Create a new user account. **New Flow (v2.0):** - Email verification is sent BEFORE user creation - If email sending fails, no user is created - Returns SERVICE_UNAVAILABLE if email service fails - User is only created if email sending succeeds requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/RegisterPayload' examples: valid_registration: summary: Valid registration value: email: 'newuser@example.com' username: 'newuser' password: 'Password123!' responses: '201': description: Successful registration (user created and email sent) content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/User' examples: register_success: summary: Successful registration value: success: true data: id: 'user_123456' email: 'newuser@example.com' username: 'newuser' role: 'user' createdAt: '2024-01-15T10:30:00.000Z' updatedAt: '2024-01-15T10:30:00.000Z' status: 201 code: 'SUCCESS' message: 'User registered successfully. Check your email to verify your account.' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '409': description: User already exists (email or username) content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: email_exists: summary: Email already exists value: success: false data: null status: 409 code: 'AUTH_EMAIL_ALREADY_EXISTS' message: 'The email is already registered' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'email' code: 'DUPLICATE' message: 'This email is already in use' username_exists: summary: Username already exists value: success: false data: null status: 409 code: 'AUTH_USER_ALREADY_EXISTS' message: 'The username is already registered' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'username' code: 'DUPLICATE' message: 'This username is already in use' '422': description: Invalid input data content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: validation_error: summary: Validation failed value: success: false data: null status: 422 code: 'VALIDATION_ERROR' message: 'The submitted data is not valid' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'validation' details: - field: 'email' code: 'INVALID_FORMAT' message: 'The email format is not valid' - field: 'username' code: 'INVALID_FORMAT' message: 'Username must contain only letters, numbers, underscores and hyphens' - field: 'password' code: 'TOO_WEAK' message: 'Password must contain at least one uppercase letter, one lowercase letter, one number and one special character' '503': description: Email service unavailable content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: email_service_failed: summary: Email service failed value: success: false data: null status: 503 code: 'SERVICE_UNAVAILABLE' message: 'Registration failed: Unable to send verification email. Please try again later.' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'email_service' code: 'SERVICE_UNAVAILABLE' message: 'Email service is temporarily unavailable' '500': description: Database error content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' default: $ref: '#/components/responses/NetworkError' /auth/verify-email/{token}: get: tags: - Authentication summary: Verify email description: Verify user account using a token parameters: - name: token in: path required: true schema: type: string example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' responses: '200': description: Email verified successfully content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/User' examples: verify_success: summary: Successful verification value: success: true data: id: 'user_123456' email: 'user@example.com' username: 'user123' role: 'user' createdAt: '2024-01-15T10:30:00.000Z' updatedAt: '2024-01-15T10:30:00.000Z' status: 200 code: 'SUCCESS' message: 'Email verified successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '400': description: Invalid token format content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_invalid: summary: Invalid token format value: success: false data: null status: 400 code: 'AUTH_TOKEN_INVALID' message: 'Invalid verification token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'INVALID' message: 'Invalid verification token' '401': description: Invalid or expired token content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_expired: summary: Expired token value: success: false data: null status: 401 code: 'AUTH_TOKEN_EXPIRED' message: 'Verification token has expired' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'EXPIRED' message: 'Verification token has expired' token_not_found: summary: Token not found value: success: false data: null status: 401 code: 'AUTH_TOKEN_INVALID' message: 'Invalid verification token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'INVALID' message: 'Invalid verification token' '409': description: User already verified content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: already_verified: summary: User already verified value: success: false data: null status: 409 code: 'AUTH_USER_ALREADY_VERIFIED' message: 'This account has already been verified' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'user' code: 'ALREADY_VERIFIED' message: 'The user is already verified' '500': description: Database update failed content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: update_failed: summary: Database update failed value: success: false data: null status: 500 code: 'AUTH_UPDATE_FAILED' message: 'Error updating verification status' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'UPDATE_FAILED' message: 'Could not update the database' default: $ref: '#/components/responses/NetworkError' /auth/verify-email-resend: post: tags: - Authentication summary: Resend verification email description: Send new verification email requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ResendVerificationPayload' responses: '200': description: Verification email resent content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: nullable: true examples: resend_success: summary: Successful resend value: success: true data: null status: 200 code: 'SUCCESS' message: 'New link sent. Check your inbox.' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '400': description: User already verified content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_already_verified: summary: User already verified value: success: false data: null status: 400 code: 'AUTH_USER_ALREADY_VERIFIED' message: 'User already verified' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'user' code: 'ALREADY_VERIFIED' message: 'User already verified' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_not_found: summary: User not found value: success: false data: null status: 404 code: 'AUTH_USER_NOT_FOUND' message: 'User not found' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'user' code: 'NOT_FOUND' message: 'User not found' '503': description: Email service unavailable content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: email_service_failed: summary: Email service failed value: success: false data: null status: 503 code: 'SERVICE_UNAVAILABLE' message: 'Unable to send verification email. Please try again later.' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'email_service' code: 'SERVICE_UNAVAILABLE' message: 'Email service is temporarily unavailable' '500': description: Database error content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' default: $ref: '#/components/responses/NetworkError' /auth/forgot-password: post: tags: - Authentication summary: Request password reset description: Send email to reset password requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ForgotPasswordPayload' responses: '200': description: Reset email sent content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: nullable: true examples: forgot_success: summary: Email sent value: success: true data: null status: 200 code: 'SUCCESS' message: 'We have sent you a link to reset your password' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_not_found: summary: User not found value: success: false data: null status: 404 code: 'AUTH_USER_NOT_FOUND' message: 'No user found with that email' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '503': description: Email service unavailable content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: email_service_failed: summary: Email service failed value: success: false data: null status: 503 code: 'SERVICE_UNAVAILABLE' message: 'Reset password failed: Unable to send reset password email. Please try again later.' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'email_service' code: 'EMAIL_SERVICE_FAILED' message: 'Email service is temporarily unavailable' '500': description: Database error content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' default: $ref: '#/components/responses/NetworkError' # ===== PASSWORD RESET FLOW ===== # New two-step password reset flow: # 1. POST /auth/reset-password/{token} - Validate token (returns validation data) # 2. PUT /auth/reset-password/{token} - Update password (requires valid token) # This provides better UX and follows REST semantics correctly. /auth/reset-password/{token}: post: tags: - Authentication summary: Validate reset token description: | Validate a password reset token before allowing password change. **Purpose:** Check if the token is valid, not expired, and associated with an existing user. This endpoint should be called before showing the password reset form to the user. parameters: - name: token in: path required: true schema: type: string example: 'abc123def456...xyz789' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ValidateResetTokenPayload' responses: '200': description: Token is valid and can be used for password reset content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/ResetTokenValidationResponse' examples: token_valid: summary: Token is valid value: success: true data: isValid: true isExpired: false userExists: true status: 200 code: 'SUCCESS' message: 'Token validation successful' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '400': description: Token validation failed (expired or malformed) content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiErrorResponse' - type: object properties: data: $ref: '#/components/schemas/ResetTokenValidationResponse' examples: token_expired: summary: Token has expired value: success: false data: isValid: false isExpired: true userExists: true status: 400 code: 'AUTH_TOKEN_EXPIRED' message: 'Token validation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'EXPIRED' message: 'Token has expired' token_malformed: summary: Token format invalid value: success: false data: isValid: false isExpired: false userExists: false status: 400 code: 'AUTH_TOKEN_INVALID' message: 'Token validation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'INVALID_FORMAT' message: 'Token format is invalid' '404': description: Token not found or user does not exist content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiErrorResponse' - type: object properties: data: $ref: '#/components/schemas/ResetTokenValidationResponse' examples: token_not_found: summary: Token not found value: success: false data: isValid: false isExpired: false userExists: false status: 404 code: 'INVALID_RESET_TOKEN' message: 'Token validation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'NOT_FOUND' message: 'Token not found or user does not exist' '500': description: Database error during validation content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' default: $ref: '#/components/responses/NetworkError' put: tags: - Authentication summary: Reset password description: | Update user password using a validated reset token. **Purpose:** Change the user's password after token validation has been successful. This endpoint should only be called after POST validation confirms the token is valid. parameters: - name: token in: path required: true schema: type: string example: 'abc123def456...xyz789' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ResetPasswordPayload' responses: '200': description: Password reset successfully content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: nullable: true examples: reset_success: summary: Password reset successful value: success: true data: null status: 200 code: 'SUCCESS' message: 'Password has been reset successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '400': description: Invalid or expired token content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_expired: summary: Token expired during process value: success: false data: null status: 400 code: 'AUTH_TOKEN_EXPIRED' message: 'The reset link has expired' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'EXPIRED' message: 'Token has expired' '404': description: Token not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_not_found: summary: Token not found value: success: false data: null status: 404 code: 'INVALID_RESET_TOKEN' message: 'Reset token not found' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'NOT_FOUND' message: 'Reset token not found' '409': description: Token already used content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_already_used: summary: Token already used value: success: false data: null status: 409 code: 'AUTH_TOKEN_ALREADY_USED' message: 'Token has already been used' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'token' code: 'ALREADY_USED' message: 'This token has already been used' '422': description: Invalid password format content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: invalid_password: summary: Password validation failed value: success: false data: null status: 422 code: 'VALIDATION_ERROR' message: 'The submitted data is not valid' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'validation' details: - field: 'password' code: 'TOO_WEAK' message: 'Password must contain at least one uppercase letter, one lowercase letter, one number and one special character' '500': description: Database error during password update content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Failed to update password in database' default: $ref: '#/components/responses/NetworkError' /auth/refresh-token: post: tags: - Authentication summary: Refresh access token description: Get new access token using refresh token requestBody: required: true content: application/json: schema: type: object required: - refreshToken properties: refreshToken: type: string example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' responses: '200': description: Token refreshed successfully content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: type: object properties: accessToken: type: string refreshToken: type: string examples: refresh_success: summary: Token refreshed value: success: true data: accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' status: 200 code: 'SUCCESS' message: 'Token refreshed successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '400': description: Missing refresh token content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: missing_refresh_token: summary: Missing refresh token value: success: false data: null status: 400 code: 'INVALID_REFRESH_TOKEN' message: 'Missing refresh token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'refreshToken' code: 'INVALID' message: 'Missing refresh token' '401': description: Invalid refresh token or user not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: invalid_refresh_token: summary: Invalid refresh token value: success: false data: null status: 401 code: 'INVALID_REFRESH_TOKEN' message: 'Invalid refresh token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'refresh_token' code: 'INVALID' message: 'Invalid refresh token' user_not_found: summary: User not found value: success: false data: null status: 401 code: 'AUTH_USER_NOT_FOUND' message: 'User not found' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'user' code: 'NOT_FOUND' message: 'User not found' '404': description: Refresh token not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: token_not_found: summary: Token not found value: success: false data: null status: 404 code: 'RESOURCE_NOT_FOUND' message: 'Resource not found' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'business' details: - field: 'refresh_token' code: 'NOT_FOUND' message: 'Refresh token not found' '500': description: Database error content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: database_error: summary: Database error value: success: false data: null status: 500 code: 'DATABASE_ERROR' message: 'Database operation failed' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'server' details: - field: 'database' code: 'DATABASE_ERROR' message: 'Database connection or operation failed' default: $ref: '#/components/responses/NetworkError' /auth/logout: post: tags: - Authentication summary: Logout description: Invalidate session tokens requestBody: required: true content: application/json: schema: type: object required: - refreshToken properties: refreshToken: type: string example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' responses: '200': description: Successful logout content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: nullable: true examples: logout_success: summary: Successful logout value: success: true data: null status: 200 code: 'SUCCESS' message: 'Session closed successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '401': description: Invalid refresh token content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: invalid_refresh_token: summary: Invalid refresh token value: success: false data: null status: 401 code: 'INVALID_REFRESH_TOKEN' message: 'Invalid refresh token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' default: $ref: '#/components/responses/NetworkError' /auth/me: get: tags: - Authentication summary: Get current user information description: Get authenticated user data security: - bearerAuth: [] responses: '200': description: User information content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/User' examples: me_success: summary: User obtained value: success: true data: id: 'user_123456' email: 'user@example.com' username: 'user123' role: 'user' createdAt: '2024-01-15T10:30:00.000Z' updatedAt: '2024-01-15T10:30:00.000Z' status: 200 code: 'SUCCESS' message: 'User obtained successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '401': description: Invalid or expired token content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: unauthorized: summary: Unauthorized value: success: false data: null status: 401 code: 'AUTH_TOKEN_INVALID' message: 'Invalid access token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' default: $ref: '#/components/responses/NetworkError' # ===== USER MANAGEMENT ===== /users: get: tags: - Users summary: Get user list description: Get users with pagination security: - bearerAuth: [] parameters: - name: page in: query schema: type: integer default: 1 example: 1 - name: limit in: query schema: type: integer default: 10 example: 10 responses: '200': description: User list content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: type: array items: $ref: '#/components/schemas/User' meta: type: object properties: pagination: type: object properties: page: type: integer limit: type: integer total: type: integer totalPages: type: integer hasNext: type: boolean hasPrev: type: boolean examples: users_list: summary: User list value: success: true data: - id: 'user_123456' email: 'user1@example.com' username: 'user1' role: 'user' createdAt: '2024-01-15T10:30:00.000Z' updatedAt: '2024-01-15T10:30:00.000Z' - id: 'user_789012' email: 'user2@example.com' username: 'user2' role: 'admin' createdAt: '2024-01-14T10:30:00.000Z' updatedAt: '2024-01-14T10:30:00.000Z' status: 200 code: 'SUCCESS' message: 'Users obtained successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' meta: pagination: page: 1 limit: 10 total: 25 totalPages: 3 hasNext: true hasPrev: false '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: unauthorized: summary: Unauthorized value: success: false data: null status: 401 code: 'AUTH_TOKEN_INVALID' message: 'Invalid access token' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' default: $ref: '#/components/responses/NetworkError' /users/{id}: get: tags: - Users summary: Get user by ID description: Get specific user information security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string example: 'user_123456' responses: '200': description: User information content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/User' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_not_found: summary: User not found value: success: false data: null status: 404 code: 'RESOURCE_NOT_FOUND' message: 'The requested user does not exist' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' default: $ref: '#/components/responses/NetworkError' put: tags: - Users summary: Update user description: Update user information security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email username: type: string role: type: string enum: [user, admin] responses: '200': description: User updated content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: $ref: '#/components/schemas/User' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_not_found: summary: User not found value: success: false data: null status: 404 code: 'RESOURCE_NOT_FOUND' message: 'The requested user does not exist' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '409': description: Email or username already exists content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: email_exists: summary: Email already exists value: success: false data: null status: 409 code: 'AUTH_USER_ALREADY_EXISTS' message: 'The email is already in use' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '422': description: Invalid input data content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: validation_error: summary: Validation failed value: success: false data: null status: 422 code: 'VALIDATION_ERROR' message: 'The submitted data is not valid' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' error: type: 'validation' details: - field: 'email' code: 'INVALID_FORMAT' message: 'The email format is not valid' - field: 'username' code: 'INVALID_FORMAT' message: 'Username must contain only letters, numbers, underscores and hyphens' default: $ref: '#/components/responses/NetworkError' delete: tags: - Users summary: Delete user description: Delete a user from the system security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string responses: '200': description: User deleted content: application/json: schema: allOf: - $ref: '#/components/schemas/ApiSuccessResponse' - type: object properties: data: nullable: true examples: delete_success: summary: User deleted value: success: true data: null status: 200 code: 'SUCCESS' message: 'User deleted successfully' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/ApiErrorResponse' examples: user_not_found: summary: User not found value: success: false data: null status: 404 code: 'RESOURCE_NOT_FOUND' message: 'The requested user does not exist' timestamp: '2024-01-15T10:30:00.000Z' requestId: '550e8400-e29b-41d4-a716-446655440000' default: $ref: '#/components/responses/NetworkError' # ===== ERROR CODES ===== # Available error codes: # AUTH_INVALID_CREDENTIALS, AUTH_USER_ALREADY_EXISTS, AUTH_USER_ALREADY_VERIFIED # AUTH_NO_ACTIVE_SESSION, AUTH_TOKEN_EXPIRED, AUTH_TOKEN_INVALID # AUTH_TOKEN_ALREADY_USED, AUTH_TOKEN_REVOKED, AUTH_TOKEN_MALICIOUS # AUTH_TOKEN_OTHER_FLOW, AUTH_FORBIDDEN, AUTH_UPDATE_FAILED # AUTH_RATE_LIMIT, AUTH_USER_NOT_FOUND, AUTH_USER_BLOCKED # INVALID_REFRESH_TOKEN, EMAIL_NOT_VERIFIED # VALIDATION_ERROR, RESOURCE_NOT_FOUND # DATABASE_ERROR # ERR_NETWORK, ERR_CANCELED, ECONNABORTED, ETIMEDOUT, UNKNOWN_ERROR # SERVICE_UNAVAILABLE