{ "openapi": "3.0.0", "info": { "title": "API Documentation & Security Implementation", "version": "1.0.0", "description": "Comprehensive documentation for secure API integration with OpenAPI standards, environment variable management, and security features including Helmet.js and CORS protection mechanisms.", "contact": { "name": "Marion Queen Ramos", "email": "marionqueen.email@example.com" } }, "servers": [ { "url": "http://localhost:3000", "description": "Development server" }, { "url": "https://api.yourdomain.com", "description": "Production server" } ], "components": { "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT", "description": "Enter your JWT token in the format: Bearer . Tokens are obtained from the authentication endpoints." } }, "schemas": { "LoanStatus": { "type": "string", "enum": [ "pending", "reviewed", "approved", "rejected" ], "description": "Represents the possible states of a resource" }, "Loan": { "type": "object", "required": [ "userId", "amount", "purpose", "status", "createdAt" ], "properties": { "id": { "type": "string", "description": "Unique identifier for the resource" }, "userId": { "type": "string", "description": "ID of the user who created the resource" }, "amount": { "type": "number", "format": "float", "description": "The requested amount" }, "purpose": { "type": "string", "description": "Purpose or reason" }, "status": { "$ref": "#/components/schemas/LoanStatus" }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp with ISO 8601 format" }, "reviewedAt": { "type": "string", "format": "date-time", "description": "Review timestamp with ISO 8601 format" }, "approvedAt": { "type": "string", "format": "date-time", "description": "Approval timestamp with ISO 8601 format" }, "riskScore": { "type": "number", "format": "float", "description": "Risk assessment score calculated for the resource" } }, "example": { "id": "123e4567-e89b-12d3-a456-426614174000", "userId": "user_abc123", "amount": 5000, "purpose": "Home renovation", "status": "pending", "createdAt": "2023-01-15T09:30:00Z" } }, "LoanRequest": { "type": "object", "required": [ "userId", "amount", "purpose" ], "properties": { "userId": { "type": "string", "description": "ID of the user creating the resource" }, "amount": { "type": "number", "format": "float", "description": "The requested amount" }, "purpose": { "type": "string", "description": "Purpose or reason" } }, "example": { "userId": "user_abc123", "amount": 5000, "purpose": "Home renovation" } }, "LoanResponse": { "type": "object", "properties": { "id": { "type": "string", "description": "Unique identifier for the resource" }, "userId": { "type": "string", "description": "ID of the user who created the resource" }, "amount": { "type": "number", "format": "float", "description": "The requested amount" }, "purpose": { "type": "string", "description": "Purpose or reason" }, "status": { "type": "string", "description": "Current status of the resource" }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp with ISO 8601 format" }, "reviewedAt": { "type": "string", "format": "date-time", "description": "Review timestamp with ISO 8601 format" }, "approvedAt": { "type": "string", "format": "date-time", "description": "Approval timestamp with ISO 8601 format" }, "riskScore": { "type": "number", "format": "float", "description": "Risk assessment score calculated for the resource" } }, "example": { "id": "123e4567-e89b-12d3-a456-426614174000", "userId": "user_abc123", "amount": 5000, "purpose": "Home renovation", "status": "pending", "createdAt": "2023-01-15T09:30:00Z" } }, "ApiResponse": { "type": "object", "required": [ "status" ], "properties": { "status": { "type": "string", "enum": [ "success", "error" ], "description": "Indicates if the operation was successful" }, "data": { "type": "object", "description": "Contains the successful operation's return data" }, "message": { "type": "string", "description": "Success message or additional context" }, "error": { "type": "string", "description": "Contains error details when status is 'error'" }, "code": { "type": "string", "description": "Used for specific error identification" } }, "example": { "status": "success", "data": { "id": "123", "status": "pending" }, "message": "Resource created successfully" } }, "ErrorResponse": { "type": "object", "required": [ "status", "error" ], "properties": { "status": { "type": "string", "enum": [ "error" ], "description": "Always 'error' for error responses" }, "message": { "type": "string", "description": "Error message describing what went wrong" }, "code": { "type": "string", "description": "Error code for client-side error handling" } }, "example": { "status": "error", "message": "Resource not found", "code": "RESOURCE_NOT_FOUND" } }, "SecurityFeatures": { "type": "object", "description": "Security implementations in this API", "properties": { "helmet": { "type": "object", "description": "Helmet.js implementation for HTTP security headers", "properties": { "contentSecurityPolicy": { "type": "boolean", "description": "Protection against XSS attacks" }, "xssFilter": { "type": "boolean", "description": "Cross-site scripting protection" }, "noSniff": { "type": "boolean", "description": "MIME type sniffing protection" }, "frameGuard": { "type": "boolean", "description": "Clickjacking protection" } } }, "cors": { "type": "object", "description": "Cross-Origin Resource Sharing configuration", "properties": { "allowedOrigins": { "type": "array", "description": "Domains allowed to access the API", "items": { "type": "string" } }, "allowedMethods": { "type": "array", "description": "HTTP methods allowed for cross-origin requests", "items": { "type": "string" } } } }, "envVars": { "type": "object", "description": "Environment variable management", "properties": { "dotenv": { "type": "boolean", "description": "Using dotenv for configuration management" }, "sensitiveDataProtection": { "type": "boolean", "description": "Sensitive data is protected in environment variables" } } } } } }, "responses": { "UnauthorizedError": { "description": "Authentication information is missing or invalid", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "string", "example": "Invalid or expired token" } } } } } }, "ForbiddenError": { "description": "User does not have sufficient permissions", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "example": "error" }, "message": { "type": "string", "example": "Access denied - Insufficient permissions" } } } } } } } }, "security": [ { "bearerAuth": [] } ], "paths": { "/api/v1/admin/users/{uid}/role": { "put": { "summary": "Set user role with secure role-based authorization", "description": "Securely changes a user's role with proper authorization checks and validation. Protected by JWT authentication and role-based access control.", "tags": [ "Authorization" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "in": "path", "name": "uid", "required": true, "schema": { "type": "string" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "role": { "type": "string", "enum": [ "user", "officer", "manager", "admin" ] } } } } } }, "responses": { "200": { "description": "User role updated successfully" }, "403": { "description": "Not authorized to perform this action" }, "404": { "description": "User not found" } } } }, "/api/v1/admin/users/{uid}": { "get": { "summary": "Get user details with secure authentication", "description": "Retrieves user information with proper authentication and authorization. Protected by JWT authentication and role verification.", "tags": [ "Authorization" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "in": "path", "name": "uid", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "User details retrieved successfully" }, "403": { "description": "Not authorized to perform this action" }, "404": { "description": "User not found" } } } }, "/api/v1/loans": { "post": { "summary": "Create resource with secure validation", "description": "Securely creates a new resource with input validation, sanitization, and proper error handling. Protected by JWT authentication and includes request validation middleware.", "tags": [ "API Resources" ], "security": [ { "bearerAuth": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoanRequest" } } } }, "responses": { "201": { "description": "Resource created successfully", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoanResponse" } } } }, "400": { "description": "Missing required fields" } } }, "get": { "summary": "List resources with role-based access control", "description": "Securely retrieves resources with role-based access control. Implements pagination and filtering with proper input validation. Protected by JWT authentication and role verification.", "tags": [ "API Resources" ], "security": [ { "bearerAuth": [] } ], "responses": { "200": { "description": "List of resources retrieved successfully", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/LoanResponse" } } } } } } } }, "/api/v1/loans/{id}/review": { "put": { "summary": "Update resource with middleware protection", "description": "Securely updates a resource with proper authorization checks. Protected by multiple middleware layers including authentication, authorization, validation, and error handling.", "tags": [ "API Resources" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "in": "path", "name": "id", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Resource updated successfully", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoanResponse" } } } }, "404": { "description": "Resource not found" } } } }, "/api/v1/loans/{id}/approve": { "put": { "summary": "Approve resource with hierarchical permissions", "description": "Demonstrates hierarchical role-based permissions with secure authentication workflow. Protected by JWT authentication and multi-level authorization checks.", "tags": [ "API Resources" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "in": "path", "name": "id", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Resource approval completed successfully", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoanResponse" } } } }, "404": { "description": "Resource not found" } } } }, "/api/docs/security-features": { "get": { "summary": "API Security Features Documentation", "description": "Provides detailed information about the security features implemented in this API including Helmet.js configuration, CORS setup, and secure environment variable management.", "tags": [ "Documentation" ], "responses": { "200": { "description": "Security features information", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SecurityFeatures" } } } } } } } }, "tags": [ { "name": "Authorization", "description": "Endpoints demonstrating secure authentication and role-based authorization" }, { "name": "API Resources", "description": "Resource endpoints with comprehensive security implementations" }, { "name": "Documentation", "description": "API documentation and security features exploration" } ] }