Axium/documentation/openapi.json

1 line
24 KiB
JSON

{"openapi":"3.1.0","info":{"title":"Axium","description":"An example API built with Rust, Axum, SQLx, and PostgreSQL.","contact":{"url":"https://github.com/Riktastic/Axium"},"license":{"name":"MIT","url":"https://opensource.org/licenses/MIT"},"version":"1.0.0"},"paths":{"/apikeys":{"get":{"tags":["apikey"],"operationId":"get_all_apikeys","parameters":[{"name":"user_id","in":"path","description":"User ID","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Get all API keys","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ApiKeyResponse"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"jwt_token":[]}]},"post":{"tags":["apikey"],"operationId":"post_apikey","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyInsertBody"}}},"required":true},"responses":{"200":{"description":"API key created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyInsertResponse"}}}},"400":{"description":"Validation error","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/apikeys/rotate/{id}":{"post":{"tags":["apikey"],"operationId":"rotate_apikey","parameters":[{"name":"id","in":"path","description":"API key identifier","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyRotateBody"}}},"required":true},"responses":{"200":{"description":"API key rotated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyRotateResponse"}}}},"400":{"description":"Validation error","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"description":"API key not found","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/apikeys/{id}":{"get":{"tags":["apikey"],"operationId":"get_apikeys_by_id","parameters":[{"name":"id","in":"path","description":"API key ID","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"user_id","in":"path","description":"User ID","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Get API key by ID","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyByIDResponse"}}}},"400":{"description":"Invalid UUID format","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"API key not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"delete":{"tags":["apikey"],"operationId":"delete_apikey_by_id","parameters":[{"name":"id","in":"path","description":"API key ID","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"API key deleted successfully","content":{"text/plain":{"schema":{"type":"string"}}}},"400":{"description":"Invalid UUID format","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"404":{"description":"API key not found","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/health":{"get":{"tags":["health"],"operationId":"get_health","responses":{"200":{"description":"Successfully fetched health status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}},"500":{"description":"Internal server error"}}}},"/protected":{"get":{"tags":["protected"],"operationId":"protected","responses":{"200":{"description":"Protected endpoint accessed successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserGetResponse"}}}},"401":{"description":"Unauthorized","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/signin":{"post":{"tags":["auth"],"summary":"User sign-in endpoint","description":"This endpoint allows users to sign in using their email, password, and optionally a TOTP code.\n\n# Parameters\n- `State(pool)`: The shared database connection pool.\n- `Json(user_data)`: The user sign-in data (email, password, and optional TOTP code).\n\n# Returns\n- `Ok(Json(serde_json::Value))`: A JSON response containing the JWT token if sign-in is successful.\n- `Err((StatusCode, Json(serde_json::Value)))`: An error response if sign-in fails.","operationId":"signin","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignInData"}}},"required":true},"responses":{"200":{"description":"Successful sign-in","content":{"application/json":{"schema":{}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{}}}}}}},"/todos":{"post":{"tags":["todo"],"operationId":"post_todo","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TodoBody"}}},"required":true},"responses":{"200":{"description":"Todo created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Todo"}}}},"400":{"description":"Validation error","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/todos/all":{"get":{"tags":["todo"],"operationId":"get_all_todos","responses":{"200":{"description":"Successfully fetched all todos","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Todo"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error"}},"security":[{"jwt_token":[]}]}},"/todos/{id}":{"get":{"tags":["todo"],"operationId":"get_todos_by_id","parameters":[{"name":"id","in":"path","description":"Todo ID","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully fetched todo by ID","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Todo"}}}},"400":{"description":"Invalid UUID format"},"404":{"description":"Todo not found"},"500":{"description":"Internal server error"}}},"delete":{"tags":["todo"],"operationId":"delete_todo_by_id","parameters":[{"name":"id","in":"path","description":"Todo ID","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"user_id","in":"path","description":"User ID","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Todo deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Invalid UUID format","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"404":{"description":"Todo not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"jwt_token":[]}]}},"/usage/lastday":{"get":{"tags":["usage"],"operationId":"get_usage_last_day","responses":{"200":{"description":"Successfully fetched usage for the last 24 hours","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageResponseLastDay"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error"}},"security":[{"jwt_token":[]}]}},"/usage/lastweek":{"get":{"tags":["usage"],"operationId":"get_usage_last_week","responses":{"200":{"description":"Successfully fetched usage for the last 7 days","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageResponseLastDay"}}}},"500":{"description":"Internal server error"}}}},"/users":{"post":{"tags":["user"],"operationId":"post_user","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserInsertBody"}}},"required":true},"responses":{"200":{"description":"User created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserInsertResponse"}}}},"400":{"description":"Validation error","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}},"security":[{"jwt_token":[]}]}},"/users/all":{"get":{"tags":["user"],"operationId":"get_all_users","responses":{"200":{"description":"Successfully fetched all users","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/UserGetResponse"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"500":{"description":"Internal server error"}},"security":[{"jwt_token":[]}]}},"/users/{id}":{"get":{"tags":["user"],"operationId":"get_users_by_id","parameters":[{"name":"id","in":"path","description":"User ID","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully fetched user by ID","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserGetResponse"}}}},"400":{"description":"Invalid UUID format"},"404":{"description":"User not found"},"500":{"description":"Internal server error"}}},"delete":{"tags":["user"],"operationId":"delete_user_by_id","parameters":[{"name":"id","in":"path","description":"User ID","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"User deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Invalid UUID format","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{}}}},"404":{"description":"User not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"jwt_token":[]}]}}},"components":{"schemas":{"ApiKey":{"type":"object","description":"Represents an API key in the system.","required":["id","key_hash","user_id","creation_date","disabled","access_read","access_modify"],"properties":{"access_modify":{"type":"boolean","description":"Whether the API key has modify access (default is false)."},"access_read":{"type":"boolean","description":"Whether the API key has read access (default is true)."},"creation_date":{"type":"string","format":"date","description":"The creation date of the API key (default is the current date)."},"description":{"type":["string","null"],"description":"The description/name of the API key."},"disabled":{"type":"boolean","description":"Whether the API key is disabled (default is false)."},"expiration_date":{"type":["string","null"],"format":"date","description":"The expiration date of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the API key."},"key_hash":{"type":"string","description":"The hashed value of the API key."},"user_id":{"type":"string","format":"uuid","description":"The id of the user who owns the API key."}}},"ApiKeyByIDResponse":{"type":"object","description":"Response body for retrieving an API key by its ID.","required":["id","creation_date"],"properties":{"creation_date":{"type":"string","format":"date","description":"The creation date of the API key."},"description":{"type":["string","null"],"description":"The description of the API key."},"expiration_date":{"type":["string","null"],"format":"date","description":"The expiration date of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the API key."}}},"ApiKeyByUserIDResponse":{"type":"object","description":"Response body for retrieving API keys by user ID.","required":["id","key_hash"],"properties":{"expiration_date":{"type":["string","null"],"format":"date","description":"The expiration date of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the API key."},"key_hash":{"type":"string","description":"The hashed value of the API key."}}},"ApiKeyGetActiveForUserResponse":{"type":"object","description":"Response body for retrieving active API keys for a user.","required":["id"],"properties":{"description":{"type":["string","null"],"description":"The description of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the API key."}}},"ApiKeyInsertBody":{"type":"object","description":"Request body for creating a new API key.","properties":{"description":{"type":["string","null"],"description":"Optional description of the API key (max 50 characters)."},"expiration_date":{"type":["string","null"],"description":"Optional expiration date of the API key (must be in the future)."}}},"ApiKeyInsertResponse":{"type":"object","description":"Response body for creating a new API key.","required":["id","api_key","description","expiration_date"],"properties":{"api_key":{"type":"string","description":"The actual API key value."},"description":{"type":"string","description":"The description of the API key."},"expiration_date":{"type":"string","description":"The expiration date of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the created API key."}}},"ApiKeyNewBody":{"type":"object","description":"Request body for creating a new API key (deprecated).","properties":{"description":{"type":["string","null"],"description":"The description of the API key."},"expiration_date":{"type":["string","null"],"format":"date","description":"The expiration date of the API key."}}},"ApiKeyResponse":{"type":"object","description":"Response body for retrieving an API key.","required":["id","user_id","creation_date"],"properties":{"creation_date":{"type":"string","format":"date","description":"The creation date of the API key."},"description":{"type":["string","null"],"description":"The description of the API key."},"expiration_date":{"type":["string","null"],"format":"date","description":"The expiration date of the API key."},"id":{"type":"string","format":"uuid","description":"The unique id of the API key."},"user_id":{"type":"string","format":"uuid","description":"The id of the user who owns the API key."}}},"ApiKeyRotateBody":{"type":"object","properties":{"description":{"type":["string","null"]},"expiration_date":{"type":["string","null"]}}},"ApiKeyRotateResponse":{"type":"object","required":["id","api_key","description","expiration_date","rotation_info"],"properties":{"api_key":{"type":"string"},"description":{"type":"string"},"expiration_date":{"type":"string","format":"date"},"id":{"type":"string","format":"uuid"},"rotation_info":{"$ref":"#/components/schemas/ApiKeyRotateResponseInfo"}}},"ApiKeyRotateResponseInfo":{"type":"object","required":["original_key","disabled_at"],"properties":{"disabled_at":{"type":"string","format":"date"},"original_key":{"type":"string","format":"uuid"}}},"Claims":{"type":"object","description":"Represents the claims to be included in a JWT payload.","required":["sub","iat","exp","iss","aud"],"properties":{"aud":{"type":"string","description":"Intended audience for the token (optional)."},"exp":{"type":"integer","description":"Timestamp when the token will expire.","minimum":0},"iat":{"type":"integer","description":"Timestamp when the token was issued.","minimum":0},"iss":{"type":"string","description":"Issuer of the token (optional)."},"sub":{"type":"string","description":"Subject of the token (e.g., user ID or email)."}}},"CpuUsage":{"type":"object","description":"Represents CPU usage information.","required":["available_percentage","status"],"properties":{"available_percentage":{"type":"string","description":"Percentage of CPU available, represented as a string."},"status":{"type":"string","description":"Status of the CPU (e.g., \"OK\", \"Warning\", \"Critical\")."}}},"DatabaseStatus":{"type":"object","description":"Represents database status information.","required":["status"],"properties":{"status":{"type":"string","description":"Status of the database (e.g., \"Connected\", \"Disconnected\")."}}},"DiskUsage":{"type":"object","description":"Represents disk usage information.","required":["status","used_percentage"],"properties":{"status":{"type":"string","description":"Status of the disk (e.g., \"OK\", \"Warning\", \"Critical\")."},"used_percentage":{"type":"string","description":"Percentage of disk space used, represented as a string."}}},"ErrorResponse":{"type":"object","description":"Represents an error response from the API.","required":["error"],"properties":{"error":{"type":"string","description":"A description of the error that occurred."}}},"HealthResponse":{"type":"object","description":"Represents the overall health status of the system.","required":["cpu_usage","database","disk_usage","memory"],"properties":{"cpu_usage":{"$ref":"#/components/schemas/CpuUsage","description":"CPU usage information."},"database":{"$ref":"#/components/schemas/DatabaseStatus","description":"Database status information."},"disk_usage":{"$ref":"#/components/schemas/DiskUsage","description":"Disk usage information."},"memory":{"$ref":"#/components/schemas/MemoryStatus","description":"Memory status information."}}},"MemoryStatus":{"type":"object","description":"Represents memory status information.","required":["available_mb","status"],"properties":{"available_mb":{"type":"integer","format":"int64","description":"Amount of available memory in megabytes."},"status":{"type":"string","description":"Status of the memory (e.g., \"OK\", \"Warning\", \"Critical\")."}}},"Role":{"type":"object","description":"Represents a user role in the system.","required":["id","level","role","name"],"properties":{"creation_date":{"type":["string","null"],"format":"date","description":"Date when the role was created."},"description":{"type":["string","null"],"description":"Description of the role."},"id":{"type":"string","format":"uuid","description":"ID of the role."},"level":{"type":"integer","format":"int32","description":"Level of the role."},"name":{"type":"string","description":"The name of the role."},"role":{"type":"string","description":"System name of the role."}}},"SignInData":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string"},"password":{"type":"string"},"totp":{"type":["string","null"]}}},"SuccessResponse":{"type":"object","description":"Represents a successful response from the API.","required":["message"],"properties":{"message":{"type":"string","description":"A message describing the successful operation."}}},"Todo":{"type":"object","description":"Represents a to-do item.","required":["id","task","user_id","creation_date"],"properties":{"completed":{"type":["boolean","null"],"description":"Whether the task is completed."},"completion_date":{"type":["string","null"],"format":"date","description":"The date the task was completed (if any)."},"creation_date":{"type":"string","format":"date","description":"The date the task was created."},"description":{"type":["string","null"],"description":"An optional detailed description of the task."},"id":{"type":"string","format":"uuid","description":"The unique identifier for the to-do item."},"task":{"type":"string","description":"The task description."},"user_id":{"type":"string","format":"uuid","description":"The unique identifier of the user who created the to-do item."}}},"TodoBody":{"type":"object","required":["task"],"properties":{"description":{"type":["string","null"]},"task":{"type":"string"}}},"UsageResponseLastDay":{"type":"object","description":"Represents the usage statistics for the last 24 hours.","required":["requests_last_24_hours"],"properties":{"requests_last_24_hours":{"type":"integer","format":"int64","description":"The number of requests made in the last 24 hours."}}},"UsageResponseLastWeek":{"type":"object","description":"Represents the usage statistics for the last 7 days.","required":["requests_last_7_days"],"properties":{"requests_last_7_days":{"type":"integer","format":"int64","description":"The number of requests made in the last 7 days."}}},"User":{"type":"object","description":"Represents a user in the system.","required":["id","username","email","password_hash","role_level","tier_level"],"properties":{"creation_date":{"type":["string","null"],"format":"date","description":"Date when the user was created."},"email":{"type":"string","description":"The email of the user."},"id":{"type":"string","format":"uuid","description":"The unique identifier for the user."},"password_hash":{"type":"string","description":"The hashed password for the user."},"role_level":{"type":"integer","format":"int32","description":"Current role of the user."},"tier_level":{"type":"integer","format":"int32","description":"Current tier level of the user."},"totp_secret":{"type":["string","null"],"description":"The TOTP secret for the user."},"username":{"type":"string","description":"The username of the user."}}},"UserGetResponse":{"type":"object","description":"Represents a user response for GET requests.","required":["id","username","email","role_level","tier_level"],"properties":{"creation_date":{"type":["string","null"],"format":"date","description":"Date when the user was created."},"email":{"type":"string","description":"The email of the user."},"id":{"type":"string","format":"uuid","description":"The unique identifier for the user."},"role_level":{"type":"integer","format":"int32","description":"Current role of the user."},"tier_level":{"type":"integer","format":"int32","description":"Current tier level of the user."},"username":{"type":"string","description":"The username of the user."}}},"UserInsertBody":{"type":"object","description":"Request body for inserting a new user.","required":["username","email","password"],"properties":{"email":{"type":"string","description":"The email of the new user."},"password":{"type":"string","description":"The password for the new user."},"totp":{"type":["string","null"],"description":"Optional TOTP secret for the new user."},"username":{"type":"string","description":"The username of the new user."}}},"UserInsertResponse":{"type":"object","description":"Response body for a successful user insertion.","required":["id","username","email","role_level","tier_level","creation_date"],"properties":{"creation_date":{"type":"string","format":"date-time","description":"The creation date and time of the newly created user."},"email":{"type":"string","description":"The email of the newly created user."},"id":{"type":"string","format":"uuid","description":"The unique identifier for the newly created user."},"role_level":{"type":"integer","format":"int32","description":"The role level assigned to the newly created user."},"tier_level":{"type":"integer","format":"int32","description":"The tier level assigned to the newly created user."},"totp_secret":{"type":["string","null"],"description":"The TOTP secret for the newly created user, if provided."},"username":{"type":"string","description":"The username of the newly created user."}}}}},"tags":[{"name":"user","description":"User related endpoints."},{"name":"apikey","description":"API key related endpoints."},{"name":"usage","description":"Usage related endpoints."},{"name":"todo","description":"Todo related endpoints."},{"name":"health","description":"Health check endpoint."}]}