1616 from litestar .connection import Request
1717 from litestar .router import Router
1818
19+
1920__all__ = (
2021 "OpenAPIRenderPlugin" ,
2122 "RapidocRenderPlugin" ,
@@ -363,6 +364,7 @@ def __init__(
363364 js_url : str | None = None ,
364365 css_url : str | None = None ,
365366 path : str | Sequence [str ] = "/scalar" ,
367+ options : dict [str , Any ] | None = None ,
366368 ** kwargs : Any ,
367369 ) -> None :
368370 """Initialize the Scalar OpenAPI UI render plugin.
@@ -375,10 +377,13 @@ def __init__(
375377 css_url: Download url for the Scalar CSS bundle.
376378 If not provided, the Litestar-provided CSS will be used.
377379 path: Path to serve the OpenAPI UI at.
380+ options: Scalar configuration options.
381+ If not provided the default Scalar configuration will be used.
378382 **kwargs: Additional arguments to pass to the base class.
379383 """
380384 self .js_url = js_url or f"https://cdn.jsdelivr.net/npm/@scalar/api-reference@{ version } "
381385 self .css_url = css_url or self ._default_css_url
386+ self .options = options
382387 super ().__init__ (path = path , ** kwargs )
383388
384389 def render (self , request : Request , openapi_schema : dict [str , Any ]) -> bytes :
@@ -412,6 +417,7 @@ def render(self, request: Request, openapi_schema: dict[str, Any]) -> bytes:
412417 id="api-reference"
413418 data-url="{ self .get_openapi_json_route (request )} ">
414419 </script>
420+ { self .render_options ()}
415421 <script src="{ self .js_url } " crossorigin></script>
416422 """
417423
@@ -423,6 +429,16 @@ def render(self, request: Request, openapi_schema: dict[str, Any]) -> bytes:
423429 </html>
424430 """ .encode ()
425431
432+ def render_options (self ) -> str :
433+ """Render options to Scalar configuration."""
434+ if not self .options :
435+ return ""
436+ return f"""
437+ <script>
438+ document.getElementById('api-reference').dataset.configuration = '{ msgspec .json .encode (self .options ).decode ()} '
439+ </script>
440+ """
441+
426442
427443class StoplightRenderPlugin (OpenAPIRenderPlugin ):
428444 """Render an OpenAPI schema using StopLight Elements."""
0 commit comments