star-openapi-elements 9.0.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- star_openapi_elements/__init__.py +0 -0
- star_openapi_elements/__version__.py +3 -0
- star_openapi_elements/plugins.py +41 -0
- star_openapi_elements/templates/__init__.py +28 -0
- star_openapi_elements/templates/elements/css/styles.min.css +1 -0
- star_openapi_elements/templates/elements/images/elements.svg +22 -0
- star_openapi_elements/templates/elements/js/web-components.min.js +2 -0
- star_openapi_elements-9.0.13.dist-info/METADATA +22 -0
- star_openapi_elements-9.0.13.dist-info/RECORD +11 -0
- star_openapi_elements-9.0.13.dist-info/WHEEL +4 -0
- star_openapi_elements-9.0.13.dist-info/entry_points.txt +2 -0
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
|
|
3
|
+
from jinja2 import Template
|
|
4
|
+
from star_openapi.plugins import BasePlugin
|
|
5
|
+
from starlette.responses import HTMLResponse
|
|
6
|
+
from starlette.routing import Route, Mount
|
|
7
|
+
from starlette.staticfiles import StaticFiles
|
|
8
|
+
|
|
9
|
+
from .templates import elements_html_string
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RegisterPlugin(BasePlugin):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self.name = "elements"
|
|
15
|
+
self.display_name = "Elements"
|
|
16
|
+
self.doc_url = "/openapi.json"
|
|
17
|
+
|
|
18
|
+
def elements_endpoint(self, request):
|
|
19
|
+
template = Template(request.app.config.get("ELEMENTS_HTML_STRING") or elements_html_string)
|
|
20
|
+
return HTMLResponse(
|
|
21
|
+
content=template.render(
|
|
22
|
+
{
|
|
23
|
+
"doc_url": self.doc_url,
|
|
24
|
+
"elements_config": request.app.config.get("ELEMENTS_CONFIG")
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def register(self, doc_url: str) -> list[Route]:
|
|
30
|
+
self.doc_url = doc_url
|
|
31
|
+
static_folder = os.path.join(os.path.dirname(__file__), "templates", "elements")
|
|
32
|
+
|
|
33
|
+
routes = [
|
|
34
|
+
Route(
|
|
35
|
+
f"/{self.name}",
|
|
36
|
+
endpoint=self.elements_endpoint
|
|
37
|
+
),
|
|
38
|
+
Mount("/elements", app=StaticFiles(directory=static_folder), name="static"),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
return routes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
elements_html_string = """
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
7
|
+
<title>Elements</title>
|
|
8
|
+
<link rel="shortcut icon" href="elements/images/elements.svg">
|
|
9
|
+
<script src="elements/js/web-components.min.js"></script>
|
|
10
|
+
<link rel="stylesheet" href="elements/css/styles.min.css">
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<elements-api
|
|
14
|
+
apiDescriptionUrl="{{ doc_url }}"
|
|
15
|
+
router="hash"
|
|
16
|
+
/>
|
|
17
|
+
<script>
|
|
18
|
+
const elements_config = JSON.parse(`{{ elements_config|default('{}')|tojson }}`);
|
|
19
|
+
var elementsDoc = document.querySelector("elements-api");
|
|
20
|
+
var specUrl = new URL("{{ doc_url }}", window.location.href).href;
|
|
21
|
+
elementsDoc.setAttribute("apiDescriptionUrl", specUrl);
|
|
22
|
+
for(var k in elements_config) {
|
|
23
|
+
elementsDoc.setAttribute(k, elements_config[k]);
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
28
|
+
"""
|