2# +==== BEGIN CatFeeder =================+
5# ...............)..(.')
7# ...............\(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
13# FILE: editor_provider.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:44:9 19-12-2025
17# This is the backend server in charge of making the actual website work.
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: Swagger Editor documentation provider implementation.
22# +==== END CatFeeder =================+
24from fastapi
import Request, Response
25from display_tty
import Disp, initialise_logger
26from .
import editor_constants
as EDITOR_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 """Swagger Editor documentation provider.
36 Provides interactive Swagger Editor for viewing and editing OpenAPI specs.
39 disp: Disp = initialise_logger(__qualname__,
False)
41 def __init__(self, openapi_url: str, api_title: str, debug: bool =
False) ->
None:
42 """Initialize Swagger Editor 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 Swagger Editor provider...")
62 self.
disp.log_debug(
"Swagger Editor provider initialised")
65 """Serve Swagger Editor documentation page.
68 request (Request): The incoming request.
71 Response: HTML response with Swagger Editor interface.
73 func_title =
"get_documentation"
74 self.
disp.log_debug(
"Serving Swagger Editor documentation", func_title)
78 self.
disp.log_debug(f
"token = {token}", func_title)
84 <meta charset="UTF-8">
85 <meta name="viewport" content="width=device-width, initial-scale=1.0">
86 <title>{self.api_title} - API Editor</title>
87 <link rel="stylesheet" href="{EDITOR_CONST.EDITOR_CDN_CSS}">
102 <div id="swagger-ui"></div>
103 <script src="{EDITOR_CONST.EDITOR_CDN_JS}"></script>
104 <script src="{EDITOR_CONST.EDITOR_CDN_PRESET}"></script>
106 window.onload = function() {{
107 if (typeof SwaggerUIBundle === 'undefined') {{
108 document.getElementById('swagger-ui').innerHTML =
109 '<div style="padding: 20px; color: red;">Editor scripts failed to load. Please check your internet connection.</div>';
113 window.ui = SwaggerUIBundle({{
114 url: '{self.openapi_url}',
115 dom_id: '#swagger-ui',
117 SwaggerUIBundle.presets.apis,
118 SwaggerUIStandalonePreset
121 SwaggerUIBundle.plugins.DownloadUrl
123 deepLinking: {str(EDITOR_CONST.EDITOR_OPTIONS.get('deepLinking', True)).lower()},
124 displayOperationId: {str(EDITOR_CONST.EDITOR_OPTIONS.get('displayOperationId', True)).lower()},
125 displayRequestDuration: {str(EDITOR_CONST.EDITOR_OPTIONS.get('displayRequestDuration', True)).lower()},
126 filter: {str(EDITOR_CONST.EDITOR_OPTIONS.get('filter', True)).lower()},
127 showExtensions: {str(EDITOR_CONST.EDITOR_OPTIONS.get('showExtensions', True)).lower()},
128 showCommonExtensions: {str(EDITOR_CONST.EDITOR_OPTIONS.get('showCommonExtensions', True)).lower()},
129 tryItOutEnabled: {str(EDITOR_CONST.EDITOR_OPTIONS.get('tryItOutEnabled', True)).lower()},
130 layout: "{EDITOR_CONST.EDITOR_OPTIONS.get('layout', 'BaseLayout')}"
137 return HCI.success(content=html_content, content_type=HttpDataTypes.HTML)
140 """Get the URL path for this documentation provider.
145 return EDITOR_CONST.EDITOR_URL
BoilerplateIncoming boilerplate_incoming_initialised
RuntimeManager runtime_manager
None __init__(self, str openapi_url, str api_title, bool debug=False)
Response get_documentation(self, Request request)
BoilerplateResponses boilerplate_responses_initialised
ServerHeaders server_headers_initialised