Skip to content

Commit 9e9e2fb

Browse files
Codex/add lru cache for get settings helper (#42)
* Cache API settings helper * Reuse cached Hygraph service * 📝 Add docstrings to `codex/add-lru_cache-for-get_settings-helper` (#38) Docstrings generation was requested by @shayancoin. * #23 (comment) The following files were modified: * `backend/api/config.py` * `backend/api/routes_sync.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 897f898 commit 9e9e2fb

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

backend/api/config.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,23 @@ def get_settings() -> Settings:
5656
def get_fastapi_settings() -> Dict[str, Any]:
5757
"""Get FastAPI application settings.
5858
59-
Returns
60-
-------
61-
Dict[str, Any]
62-
Dictionary with FastAPI settings.
59+
60+
def get_fastapi_settings() -> Dict[str, Any]:
61+
"""
62+
Provide FastAPI application metadata and routing configuration for documentation UIs.
63+
64+
Returns:
65+
fastapi_settings (Dict[str, Any]): Mapping containing:
66+
- title: API display title.
67+
- description: Short API description.
68+
- version: API semantic version string.
69+
- docs_url: URL path for the Swagger UI.
70+
- redoc_url: URL path for the ReDoc UI.
6371
"""
6472
return {
6573
"title": "MVP API",
6674
"description": "API for MVP application",
6775
"version": "0.1.0",
6876
"docs_url": "/docs",
6977
"redoc_url": "/redoc",
70-
}
78+
}

backend/api/routes_sync.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ def get_hygraph_service() -> HygraphService:
4343

4444
return _hygraph_service
4545
def _error_envelope(code: str, message: str, details: Optional[dict] = None) -> Dict[str, Any]:
46+
"""
47+
Builds a standardized error envelope for API responses.
48+
49+
Parameters:
50+
code (str): Machine-readable error code identifying the error.
51+
message (str): Human-readable error message describing the failure.
52+
details (Optional[dict]): Additional contextual information; defaults to an empty dict when not provided.
53+
54+
Returns:
55+
Dict[str, Any]: Dictionary with keys `ok` (False) and `error` containing `code`, `message`, and `details`.
56+
"""
4657
return {"ok": False, "error": {"code": code, "message": message, "details": details or {}}}
4758

4859

0 commit comments

Comments
 (0)