star-openapi-scalar 1.40.9__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_scalar/__init__.py +0 -0
- star_openapi_scalar/__version__.py +3 -0
- star_openapi_scalar/plugins.py +41 -0
- star_openapi_scalar/templates/__init__.py +26 -0
- star_openapi_scalar/templates/scalar/images/scalar.svg +4 -0
- star_openapi_scalar/templates/scalar/js/scalar.standalone.js +47 -0
- star_openapi_scalar-1.40.9.dist-info/METADATA +22 -0
- star_openapi_scalar-1.40.9.dist-info/RECORD +10 -0
- star_openapi_scalar-1.40.9.dist-info/WHEEL +4 -0
- star_openapi_scalar-1.40.9.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 scalar_html_string
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RegisterPlugin(BasePlugin):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self.name = "scalar"
|
|
15
|
+
self.display_name = "Scalar"
|
|
16
|
+
self.doc_url = "/openapi.json"
|
|
17
|
+
|
|
18
|
+
def scalar_endpoint(self, request):
|
|
19
|
+
template = Template(request.app.config.get("SCALAR_HTML_STRING") or scalar_html_string)
|
|
20
|
+
return HTMLResponse(
|
|
21
|
+
content=template.render(
|
|
22
|
+
{
|
|
23
|
+
"doc_url": self.doc_url,
|
|
24
|
+
"scalar_config": request.app.config.get("SCALAR_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", "scalar")
|
|
32
|
+
|
|
33
|
+
routes = [
|
|
34
|
+
Route(
|
|
35
|
+
f"/{self.name}",
|
|
36
|
+
endpoint=self.scalar_endpoint
|
|
37
|
+
),
|
|
38
|
+
Mount("/scalar", app=StaticFiles(directory=static_folder), name="static"),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
return routes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
scalar_html_string = """
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>Scalar API</title>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
<meta
|
|
8
|
+
name="viewport"
|
|
9
|
+
content="width=device-width, initial-scale=1" />
|
|
10
|
+
<link rel="shortcut icon" href="scalar/images/scalar.svg">
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<script
|
|
14
|
+
id="api-reference"
|
|
15
|
+
data-url="{{ doc_url }}">
|
|
16
|
+
</script>
|
|
17
|
+
<script>
|
|
18
|
+
const scalar_config = JSON.parse(`{{ scalar_config|default('{}')|tojson }}`);
|
|
19
|
+
var configuration = {...scalar_config};
|
|
20
|
+
var apiReference = document.getElementById('api-reference');
|
|
21
|
+
apiReference.dataset.configuration = JSON.stringify(configuration);
|
|
22
|
+
</script>
|
|
23
|
+
<script src="scalar/js/scalar.standalone.js"></script>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
26
|
+
"""
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 593 593">
|
|
2
|
+
<path fill="black" fill-rule="evenodd"
|
|
3
|
+
d="M347 0c6 0 12 5 12 12v134l94-95c5-5 13-5 17 0l72 72c4 4 5 12 0 16v1l-95 94h134c7 0 12 5 12 12v101c0 7-5 12-12 12H447l95 94c4 5 5 13 0 17l-72 72c-4 4-12 5-16 0h-1l-94-95v134c0 7-5 12-12 12H246c-7 0-12-5-12-12v-70c0-22 9-43 24-59l130-130c14-14 14-37 0-51L259 142a84 84 0 0 1-25-59V12c0-7 5-12 12-12h101ZM138 52h1l219 219c14 14 14 37 0 51L139 542c-4 5-12 5-17 0l-71-70c-4-5-5-12 0-17l95-96H12c-7 0-12-5-12-12V246c0-7 5-12 12-12h134l-95-94c-4-5-4-12 0-17l71-71c4-5 12-5 16 0Z" />
|
|
4
|
+
</svg>
|