mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Complete autoswagger!
This commit is contained in:
parent
7bb3db0145
commit
668df043f4
3 changed files with 18 additions and 4 deletions
|
@ -6,5 +6,7 @@ from royalnet.version import semantic
|
|||
class ApiDocsStar(ApiStar):
|
||||
path = "/api/docs"
|
||||
|
||||
summary = "Get the swagger.json file used to generate this documentation."
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
return
|
||||
|
|
|
@ -11,14 +11,21 @@ class DocsStar(PageStar):
|
|||
path = "/docs"
|
||||
|
||||
async def page(self, request: Request) -> Response:
|
||||
paths = {}
|
||||
|
||||
for star in self.constellation.stars:
|
||||
if not isinstance(star, ApiStar):
|
||||
continue
|
||||
paths[star.path] = star.swagger()
|
||||
|
||||
spec = json.dumps({
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "Autogenerated Royalnet API documentation",
|
||||
"title": "Royalnet",
|
||||
"version": f"{semantic}",
|
||||
"paths": [star.swagger() for star in self.constellation.stars if isinstance(star, ApiStar)]
|
||||
}
|
||||
},
|
||||
"paths": paths
|
||||
})
|
||||
|
||||
return HTMLResponse(
|
||||
|
@ -26,17 +33,21 @@ class DocsStar(PageStar):
|
|||
<html lang="en">
|
||||
<head>
|
||||
<title>Royalnet Docs</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui.css">
|
||||
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-standalone-preset.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="docs"/>
|
||||
<script>
|
||||
const ui = SwaggerUIBundle({{
|
||||
spec: {spec}
|
||||
spec: JSON.parse('{spec}'),
|
||||
dom_id: '#docs',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
}})
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -53,6 +53,7 @@ class ApiStar(PageStar, ABC):
|
|||
result = {}
|
||||
for method in cls.methods:
|
||||
result[method.lower()] = {
|
||||
"operationId": cls.__name__,
|
||||
"summary": cls.summary,
|
||||
"description": cls.description,
|
||||
"produces": ["application/json"],
|
||||
|
@ -64,7 +65,7 @@ class ApiStar(PageStar, ABC):
|
|||
"500": {"description": "Serverside unhandled exception"},
|
||||
"501": {"description": "Not yet implemented"}
|
||||
},
|
||||
"paameters": [{
|
||||
"parameters": [{
|
||||
"name": parameter,
|
||||
"in": "query",
|
||||
"description": cls.parameters[parameter],
|
||||
|
|
Loading…
Reference in a new issue