2# +==== BEGIN CatFeeder =================+
5# ...............)..(.')
7# ...............\(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
13# FILE: explorer_provider.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:44:44 19-12-2025
17# This is the backend server in charge of making the actual website work.
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: OpenAPI Explorer documentation provider implementation.
22# +==== END CatFeeder =================+
24from fastapi
import Request, Response
25from display_tty
import Disp, initialise_logger
26from .
import explorer_constants
as EXPLORER_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 """OpenAPI Explorer documentation provider.
36 Provides interactive API explorer with request/response console.
39 disp: Disp = initialise_logger(__qualname__,
False)
41 def __init__(self, openapi_url: str, api_title: str, debug: bool =
False) ->
None:
42 """Initialize OpenAPI Explorer 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 OpenAPI Explorer provider...")
62 self.
disp.log_debug(
"OpenAPI Explorer provider initialised")
65 """Serve OpenAPI Explorer documentation page.
68 request (Request): The incoming request.
71 Response: HTML response with OpenAPI Explorer interface.
73 func_title =
"get_documentation"
75 "Serving OpenAPI Explorer documentation", func_title)
79 self.
disp.log_debug(f
"token = {token}", func_title)
82 for key, value
in EXPLORER_CONST.EXPLORER_OPTIONS.items():
83 if isinstance(value, bool):
88 elif isinstance(value, str):
89 js_value = f
'"{value}"'
92 options_js = options_js + f
" {key}: {js_value},\n"
98 <meta charset="UTF-8">
99 <meta name="viewport" content="width=device-width, initial-scale=1.0">
100 <title>{self.api_title} - OpenAPI Explorer</title>
101 <link rel="stylesheet" href="{EXPLORER_CONST.EXPLORER_CDN_CSS}">
114 <div id="explorer"></div>
115 <script src="{EXPLORER_CONST.EXPLORER_CDN_JS}"></script>
116 <script src="{EXPLORER_CONST.EXPLORER_CDN_PRESET}"></script>
118 window.onload = function() {{
119 window.ui = SwaggerUIBundle({{
120 url: '{self.openapi_url}',
122{options_js} presets: [
123 SwaggerUIBundle.presets.apis,
124 SwaggerUIStandalonePreset
127 SwaggerUIBundle.plugins.DownloadUrl
135 return HCI.success(content=html_content, content_type=HttpDataTypes.HTML)
138 """Get the URL path for this documentation provider.
143 return EXPLORER_CONST.EXPLORER_URL
BoilerplateResponses boilerplate_responses_initialised
Response get_documentation(self, Request request)
BoilerplateIncoming boilerplate_incoming_initialised
RuntimeManager runtime_manager
None __init__(self, str openapi_url, str api_title, bool debug=False)
ServerHeaders server_headers_initialised