docs: add OpenAPI responses={} to all router endpoints
Add explicit HTTP status code documentation to every endpoint across 15 router files. Each endpoint now declares all possible response codes (200/201/204/400/401/404/409/429/502/503) with descriptions so frontend can distinguish error types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -111,6 +111,11 @@ def _validate_log_target(value: str) -> None:
|
||||
"/global",
|
||||
response_model=GlobalConfigResponse,
|
||||
summary="Return global fail2ban settings",
|
||||
responses={
|
||||
200: {"description": "Global config returned", "model": GlobalConfigResponse},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
502: {"description": "fail2ban unreachable"},
|
||||
},
|
||||
)
|
||||
async def get_global_config(
|
||||
_request: Request,
|
||||
@@ -140,6 +145,13 @@ async def get_global_config(
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
summary="Update global fail2ban settings",
|
||||
dependencies=[Depends(_check_config_update_rate_limit)],
|
||||
responses={
|
||||
204: {"description": "Global config updated successfully"},
|
||||
400: {"description": "Set command rejected or log_target invalid"},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
429: {"description": "Rate limit exceeded for config update operations"},
|
||||
502: {"description": "fail2ban unreachable"},
|
||||
},
|
||||
)
|
||||
async def update_global_config(
|
||||
_request: Request,
|
||||
@@ -171,6 +183,12 @@ async def update_global_config(
|
||||
"/reload",
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
summary="Reload fail2ban to apply configuration changes",
|
||||
responses={
|
||||
204: {"description": "Fail2ban reloaded successfully"},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
409: {"description": "Reload command failed in fail2ban"},
|
||||
502: {"description": "fail2ban unreachable"},
|
||||
},
|
||||
)
|
||||
async def reload_fail2ban(
|
||||
_request: Request,
|
||||
@@ -199,6 +217,13 @@ async def reload_fail2ban(
|
||||
"/restart",
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
summary="Restart the fail2ban service",
|
||||
responses={
|
||||
204: {"description": "Fail2ban restarted successfully"},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
409: {"description": "Stop command failed in fail2ban"},
|
||||
502: {"description": "fail2ban unreachable for stop command"},
|
||||
503: {"description": "fail2ban did not come back online within 10s"},
|
||||
},
|
||||
)
|
||||
async def restart_fail2ban(
|
||||
_request: Request,
|
||||
@@ -252,6 +277,11 @@ async def restart_fail2ban(
|
||||
"/regex-test",
|
||||
response_model=RegexTestResponse,
|
||||
summary="Test a fail regex pattern against a sample log line",
|
||||
responses={
|
||||
200: {"description": "Regex test result", "model": RegexTestResponse},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
422: {"description": "Invalid regex pattern"},
|
||||
},
|
||||
)
|
||||
async def regex_test(
|
||||
_auth: AuthDep,
|
||||
@@ -281,6 +311,11 @@ async def regex_test(
|
||||
"/preview-log",
|
||||
response_model=LogPreviewResponse,
|
||||
summary="Preview log file lines against a regex pattern",
|
||||
responses={
|
||||
200: {"description": "Log preview result", "model": LogPreviewResponse},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
422: {"description": "Invalid regex pattern"},
|
||||
},
|
||||
)
|
||||
async def preview_log(
|
||||
_auth: AuthDep,
|
||||
@@ -310,6 +345,10 @@ async def preview_log(
|
||||
"/map-color-thresholds",
|
||||
response_model=MapColorThresholdsResponse,
|
||||
summary="Get map color threshold configuration",
|
||||
responses={
|
||||
200: {"description": "Color thresholds returned", "model": MapColorThresholdsResponse},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
},
|
||||
)
|
||||
async def get_map_color_thresholds(
|
||||
_request: Request,
|
||||
@@ -334,6 +373,12 @@ async def get_map_color_thresholds(
|
||||
response_model=MapColorThresholdsResponse,
|
||||
summary="Update map color threshold configuration",
|
||||
dependencies=[Depends(_check_config_update_rate_limit)],
|
||||
responses={
|
||||
200: {"description": "Color thresholds updated", "model": MapColorThresholdsResponse},
|
||||
400: {"description": "Validation error (thresholds not properly ordered)"},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
429: {"description": "Rate limit exceeded for config update operations"},
|
||||
},
|
||||
)
|
||||
async def update_map_color_thresholds(
|
||||
_request: Request,
|
||||
@@ -365,6 +410,12 @@ async def update_map_color_thresholds(
|
||||
"/fail2ban-log",
|
||||
response_model=Fail2BanLogResponse,
|
||||
summary="Read the tail of the fail2ban daemon log file",
|
||||
responses={
|
||||
200: {"description": "Log file lines returned", "model": Fail2BanLogResponse},
|
||||
400: {"description": "Log target not a file or path outside allowed directory"},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
502: {"description": "fail2ban unreachable"},
|
||||
},
|
||||
)
|
||||
async def get_fail2ban_log(
|
||||
_request: Request,
|
||||
@@ -416,6 +467,11 @@ async def get_fail2ban_log(
|
||||
"/service-status",
|
||||
response_model=ServiceStatusResponse,
|
||||
summary="Return fail2ban service health status with log configuration",
|
||||
responses={
|
||||
200: {"description": "Service status returned", "model": ServiceStatusResponse},
|
||||
401: {"description": "Session missing, expired, or invalid"},
|
||||
502: {"description": "fail2ban unreachable"},
|
||||
},
|
||||
)
|
||||
async def get_service_status(
|
||||
_request: Request,
|
||||
|
||||
Reference in New Issue
Block a user