Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
rapidoc_provider.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: rapidoc_provider.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:44:59 19-12-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: RapiDoc documentation provider implementation.
21# // AR
22# +==== END CatFeeder =================+
23"""
24from fastapi import Request, Response
25from display_tty import Disp, initialise_logger
26from . import rapidoc_constants as RAPIDOC_CONST
27from ...http_codes import HCI, HttpDataTypes
28from ...core.runtime_manager import RuntimeManager, RI
29from ...server_header import ServerHeaders
30from ...boilerplates import BoilerplateResponses, BoilerplateIncoming
31
32
34 """RapiDoc documentation provider.
35
36 Provides RapiDoc API documentation interface with customizable layouts.
37 """
38
39 disp: Disp = initialise_logger(__qualname__, False)
40
41 def __init__(self, openapi_url: str, api_title: str, debug: bool = False) -> None:
42 """Initialize RapiDoc provider.
43
44 Args:
45 openapi_url (str): URL to OpenAPI JSON schema.
46 api_title (str): Title of the API.
47 debug (bool, optional): Enable debug logging. Defaults to False.
48 """
49 self.disp.update_disp_debug(debug)
50 self.disp.log_debug("Initialising RapiDoc provider...")
51
52 self.openapi_url = openapi_url
53 self.api_title = api_title
54 self.runtime_manager: RuntimeManager = RI
55 self.server_headers_initialised: ServerHeaders = self.runtime_manager.get(
56 ServerHeaders)
57 self.boilerplate_responses_initialised: BoilerplateResponses = self.runtime_manager.get(
58 BoilerplateResponses)
59 self.boilerplate_incoming_initialised: BoilerplateIncoming = self.runtime_manager.get(
60 BoilerplateIncoming)
61
62 self.disp.log_debug("RapiDoc provider initialised")
63
64 async def get_documentation(self, request: Request) -> Response:
65 """Serve RapiDoc documentation page.
66
67 Args:
68 request (Request): The incoming request.
69
70 Returns:
71 Response: HTML response with RapiDoc interface.
72 """
73 func_title = "get_documentation"
74 self.disp.log_debug("Serving RapiDoc documentation", func_title)
75
76 token = self.boilerplate_incoming_initialised.get_token_if_present(
77 request)
78 self.disp.log_debug(f"token = {token}", func_title)
79
80 options_str = " ".join(
81 [f'{key}="{value}"' for key, value in RAPIDOC_CONST.RAPIDOC_OPTIONS.items()])
82
83 html_content = f"""
84<!DOCTYPE html>
85<html>
86<head>
87 <meta charset="utf-8">
88 <meta name="viewport" content="width=device-width, initial-scale=1">
89 <title>{self.api_title} - RapiDoc</title>
90 <script type="module" src="{RAPIDOC_CONST.RAPIDOC_CDN_URL}"></script>
91</head>
92<body>
93 <rapi-doc
94 spec-url="{self.openapi_url}"
95 render-style="{RAPIDOC_CONST.RAPIDOC_RENDER_STYLE}"
96 layout="{RAPIDOC_CONST.RAPIDOC_LAYOUT}"
97 theme="{RAPIDOC_CONST.RAPIDOC_THEME}"
98 schema-style="{RAPIDOC_CONST.RAPIDOC_SCHEMA_STYLE}"
99 {options_str}
100 ></rapi-doc>
101</body>
102</html>
103"""
104 return HCI.success(content=html_content, content_type=HttpDataTypes.HTML)
105
106 def get_url(self) -> str:
107 """Get the URL path for this documentation provider.
108
109 Returns:
110 str: The URL path.
111 """
112 return RAPIDOC_CONST.RAPIDOC_URL
None __init__(self, str openapi_url, str api_title, bool debug=False)