Skip to content

Commit 8bf1715

Browse files
authored
fix: dump spec as a JSON (#467)
Signed-off-by: Keming <kemingy94@gmail.com>
1 parent 7ec5733 commit 8bf1715

4 files changed

Lines changed: 353 additions & 284 deletions

File tree

spectree/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def openapi_info(self) -> Dict[str, str]:
154154
"license",
155155
},
156156
exclude_none=True,
157+
mode="json",
157158
)
158159
if info.get("terms_of_service") is not None:
159160
info["termsOfService"] = info.pop("terms_of_service")

spectree/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</head>
2424
<body>
2525
<redoc spec-url='{spec_url}'></redoc>
26-
<script type="module" src="https://cdn.redoc.ly/redoc/v2.5.1/bundles/redoc.standalone.js"> </script>
26+
<script src="https://unpkg.com/redoc@v2.5.1/bundles/redoc.standalone.js"> </script>
2727
</body>
2828
</html>""",
2929
# https://swagger.io

spectree/plugins/falcon_plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ImportError:
1515
from io import BytesIO as CachedFile # type: ignore[assignment]
1616

17-
from falcon import MEDIA_JSON, http_status_to_code
17+
from falcon import MEDIA_HTML, MEDIA_JSON, http_status_to_code
1818
from falcon import Request as FalconRequest
1919
from falcon import Response as FalconResponse
2020
from falcon.asgi import Request as FalconASGIRequest
@@ -82,16 +82,17 @@ def __init__(self, spec: Mapping[str, str]):
8282
self.spec = spec
8383

8484
def on_get(self, _: Any, resp: Any):
85+
resp.content_type = MEDIA_JSON
8586
resp.media = self.spec
8687

8788

8889
class DocPage:
8990
def __init__(self, html: str, **kwargs: Any):
90-
self.page = html.format(**kwargs)
91+
self.page = html.format(**kwargs).encode("utf-8")
9192

9293
def on_get(self, _: Any, resp: Any):
93-
resp.content_type = "text/html"
94-
resp.text = self.page
94+
resp.content_type = MEDIA_HTML
95+
resp.data = self.page
9596

9697

9798
class OpenAPIAsgi(OpenAPI):

0 commit comments

Comments
 (0)