diff --git a/README.rst b/README.rst index 4d45dbf..7a43c57 100644 --- a/README.rst +++ b/README.rst @@ -53,8 +53,10 @@ methods. The documentation is served by default at ``/openapi.json`` according to the OpenAPI standard, or at ``/docs`` for a `SwaggerUI `_ interface, or ``/redocs`` for -a `redoc `_ interface. Note that -there is currently no documentation standard for WebSockets. +a `redoc `_ interface, or +``/scalar`` for a `ScalaR `_ +interface. Note that there is currently no documentation standard for +WebSockets. Contributing ------------ diff --git a/src/quart_schema/extension.py b/src/quart_schema/extension.py index d94280b..1c674a9 100644 --- a/src/quart_schema/extension.py +++ b/src/quart_schema/extension.py @@ -84,6 +84,21 @@ """ +SCALAR_TEMPLATE = """ + + {{ title }} + + + + + + +""" + SWAGGER_TEMPLATE = """ @@ -159,6 +174,8 @@ def create_app(): to disable documentation. redoc_ui_path: The path used to serve the documentation UI using redoc or None to disable redoc documentation. + scalar_ui_path: The path used to serve the documentation UI using + scalar or None to disable scalar documentation. swagger_ui_path: The path used to serve the documentation UI using swagger or None to disable swagger documentation. info: A OpenAPI Info object describing the API. @@ -176,6 +193,7 @@ def __init__( *, openapi_path: Optional[str] = "/openapi.json", redoc_ui_path: Optional[str] = "/redocs", + scalar_ui_path: Optional[str] = "/scalar", swagger_ui_path: Optional[str] = "/docs", info: Optional[Union[Info, dict]] = None, tags: Optional[List[Union[Tag, dict]]] = None, @@ -188,6 +206,7 @@ def __init__( ) -> None: self.openapi_path = openapi_path self.redoc_ui_path = redoc_ui_path + self.scalar_ui_path = scalar_ui_path self.swagger_ui_path = swagger_ui_path self.convert_casing = convert_casing @@ -263,6 +282,10 @@ def init_app(self, app: Quart) -> None: "QUART_SCHEMA_REDOC_JS_URL", "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js", ) + app.config.setdefault( + "QUART_SCHEMA_SCALAR_JS_URL", + "https://cdn.jsdelivr.net/npm/@scalar/api-reference", + ) app.config.setdefault("QUART_SCHEMA_BY_ALIAS", False) app.config.setdefault("QUART_SCHEMA_CONVERT_CASING", self.convert_casing) app.config.setdefault("QUART_SCHEMA_CONVERSION_PREFERENCE", self.conversion_preference) @@ -271,6 +294,8 @@ def init_app(self, app: Quart) -> None: app.add_url_rule(self.openapi_path, "openapi", self.openapi) if self.redoc_ui_path is not None: app.add_url_rule(self.redoc_ui_path, "redoc_ui", self.redoc_ui) + if self.scalar_ui_path is not None: + app.add_url_rule(self.scalar_ui_path, "scalar_ui", self.scalar_ui) if self.swagger_ui_path is not None: app.add_url_rule(self.swagger_ui_path, "swagger_ui", self.swagger_ui) @@ -299,6 +324,15 @@ async def redoc_ui(self) -> str: redoc_js_url=current_app.config["QUART_SCHEMA_REDOC_JS_URL"], ) + @hide + async def scalar_ui(self) -> str: + return await render_template_string( + SCALAR_TEMPLATE, + title=self.info.title, + openapi_path=self.openapi_path, + scalar_js_url=current_app.config["QUART_SCHEMA_SCALAR_JS_URL"], + ) + @click.command("schema") @click.option(