2# +==== BEGIN CatFeeder =================+
5# ...............)..(.')
7# ...............\(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
13# FILE: elements_provider.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:44:27 19-12-2025
17# This is the backend server in charge of making the actual website work.
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: Stoplight Elements documentation provider implementation.
22# +==== END CatFeeder =================+
24from fastapi
import Request, Response
25from display_tty
import Disp, initialise_logger
26from .
import elements_constants
as ELEMENTS_CONST
27from ...http_codes
import HCI, HttpDataTypes
28from ...core.runtime_manager
import RuntimeManager, RI
29from ...server_header
import ServerHeaders
30from ...boilerplates
import BoilerplateResponses, BoilerplateIncoming
34 """Stoplight Elements documentation provider.
36 Provides beautiful API documentation using Stoplight Elements web components.
39 disp: Disp = initialise_logger(__qualname__,
False)
41 def __init__(self, openapi_url: str, api_title: str, debug: bool =
False) ->
None:
42 """Initialize Stoplight Elements provider.
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.
49 self.
disp.update_disp_debug(debug)
50 self.
disp.log_debug(
"Initialising Stoplight Elements provider...")
62 self.
disp.log_debug(
"Stoplight Elements provider initialised")
65 """Serve Stoplight Elements documentation page.
68 request (Request): The incoming request.
71 Response: HTML response with Stoplight Elements interface.
73 func_title =
"get_documentation"
75 "Serving Stoplight Elements documentation", func_title)
79 self.
disp.log_debug(f
"token = {token}", func_title)
82 for key, value
in ELEMENTS_CONST.ELEMENTS_OPTIONS.items():
84 if isinstance(value, bool):
90 attr_value = str(value)
91 attributes_str = attributes_str + \
92 f
' {attr_name}="{attr_value}"\n'
98 <meta charset="utf-8">
99 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
100 <title>{self.api_title} - Stoplight Elements</title>
101 <link rel="stylesheet" href="{ELEMENTS_CONST.ELEMENTS_CDN_CSS}">
111 apiDescriptionUrl="{self.openapi_url}"
112 router="{ELEMENTS_CONST.ELEMENTS_ROUTER}"
113 layout="{ELEMENTS_CONST.ELEMENTS_LAYOUT}"
115 <script src="{ELEMENTS_CONST.ELEMENTS_CDN_JS}"></script>
119 return HCI.success(content=html_content, content_type=HttpDataTypes.HTML)
122 """Get the URL path for this documentation provider.
127 return ELEMENTS_CONST.ELEMENTS_URL
BoilerplateIncoming boilerplate_incoming_initialised
None __init__(self, str openapi_url, str api_title, bool debug=False)
Response get_documentation(self, Request request)
RuntimeManager runtime_manager
ServerHeaders server_headers_initialised
BoilerplateResponses boilerplate_responses_initialised