plugins#

class litestar.openapi.plugins.OpenAPIRenderPlugin#

Bases: ABC

Base class for OpenAPI UI render plugins.

__init__(*, path: str | Sequence[str], media_type: MediaType | OpenAPIMediaType = MediaType.HTML, favicon: str = "<link rel='icon' type='image/png' href='https://cdn.jsdelivr.net/gh/litestar-org/branding@main/assets/Branding%20-%20PNG%20-%20Transparent/Badge%20-%20Blue%20and%20Yellow.png'>", style: str = '<style>body { margin: 0; padding: 0 }</style>') None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • path – Path to serve the OpenAPI UI at.

  • media_type – Media type for the handler.

  • favicon – Html <link> tag for the favicon.

  • style – Base styling of the html body.

static render_json(request: Request, openapi_schema: dict[str, Any]) bytes#

Render the OpenAPI schema as JSON.

Parameters:
  • request – The request that triggered the render.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

The rendered JSON.

abstract render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render the OpenAPI UI.

Parameters:
  • request – The request that triggered the render.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

The rendered HTML.

static get_openapi_json_route(request: Request) str#

Get the route for the OpenAPI JSON schema.

Returns:

The route for the OpenAPI JSON schema.

receive_router(router: Router) None#

Receive the router that serves the OpenAPI UI.

Can be used by plugins to additionally configure the router, e.g. to add additional routes.

Parameters:

router – The router that serves the OpenAPI UI.

has_path(path: str) bool#

Check if the plugin has a path.

Parameters:

path – The path to check.

Returns:

True if the plugin has the path, False otherwise.

class litestar.openapi.plugins.RapidocRenderPlugin#

Bases: OpenAPIRenderPlugin

Render an OpenAPI schema using Rapidoc.

__init__(*, version: str = '9.3.4', js_url: str | None = None, path: str | Sequence[str] = '/rapidoc', **kwargs: Any) None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • version – Rapidoc version to download from the CDN. If js_url is provided, this is ignored.

  • js_url – Download url for the RapiDoc JS bundle. If not provided, the version will be used to construct the url.

  • path – Path to serve the OpenAPI UI at.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an HTML page for Rapidoc.

Note

Override this method to customize the template.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

A rendered html string.

class litestar.openapi.plugins.RedocRenderPlugin#

Bases: OpenAPIRenderPlugin

Render an OpenAPI schema using Redoc.

__init__(*, version: str = 'next', js_url: str | None = None, google_fonts: bool = True, path: str | Sequence[str] = '/redoc', **kwargs: Any) None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • version – Redoc version to download from the CDN. If js_url is provided, this is ignored.

  • js_url – Download url for the Redoc JS bundle. If not provided, the version will be used to construct the url.

  • google_fonts – Download google fonts via CDN. Should be set to False when not using a CDN.

  • path – Path to serve the OpenAPI UI at.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an HTML page for Redoc.

Note

override this method to customize the template.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

A rendered html string.

class litestar.openapi.plugins.ScalarRenderPlugin#

Bases: OpenAPIRenderPlugin

Plugin to render an OpenAPI schema using Scalar.

New in version 2.8.0.

__init__(*, version: str = 'latest', js_url: str | None = None, css_url: str | None = None, path: str | Sequence[str] = '/scalar', **kwargs: Any) None#

Initialize the Scalar OpenAPI UI render plugin.

Parameters:
  • version – Scalar version to download from the CDN. If js_url is provided, this is ignored.

  • js_url – Download url for the Scalar JS bundle. If not provided, the version will be used to construct the url.

  • css_url – Download url for the Scalar CSS bundle. If not provided, the Litestar-provided CSS will be used.

  • path – Path to serve the OpenAPI UI at.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an HTMl page for Scalar.

Note

Override this method to customize the template.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

A rendered html string.

class litestar.openapi.plugins.StoplightRenderPlugin#

Bases: OpenAPIRenderPlugin

Render an OpenAPI schema using StopLight Elements.

__init__(*, version: str = '7.7.18', js_url: str | None = None, css_url: str | None = None, path: str | Sequence[str] = '/elements', **kwargs: Any) None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • version – StopLight Elements version to download from the CDN. If js_url is provided, this is ignored.

  • js_url – Download url for the StopLight Elements JS bundle. If not provided, the version will be used to construct the url.

  • css_url – Download url for the StopLight Elements CSS bundle. If not provided, the version will be used to construct the url.

  • path – Path to serve the OpenAPI UI at.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an HTML page for StopLight Elements.

Note

Override this method to customize the template.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

A rendered html string.

class litestar.openapi.plugins.SwaggerRenderPlugin#

Bases: OpenAPIRenderPlugin

Render an OpenAPI schema using Swagger-UI.

__init__(version: str = '5.1.3', js_url: str | None = None, css_url: str | None = None, standalone_preset_js_url: str | None = None, init_oauth: dict[str, Any] | bytes | None = None, path: str | Sequence[str] = '/swagger', **kwargs: Any) None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • version – SwaggerUI version to download from the CDN. If js_url is provided, this is ignored.

  • js_url – Download url for the Swagger UI JS bundle. If not provided, the version will be used to construct the url.

  • css_url – Download url for the Swagger UI CSS bundle. If not provided, the version will be used to construct the url.

  • standalone_preset_js_url – Download url for the Swagger Standalone Preset JS bundle. If not provided, the version will be used to construct the url.

  • init_oauth – JSON to initialize Swagger UI OAuth2 by calling the initOAuth method. Refer to the following URL for details: Swagger-UI.

  • path – Path to serve the OpenAPI UI at.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an HTML page for Swagger-UI.

Notes

  • override this method to customize the template.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

A rendered html string.

receive_router(router: Router) None#

Receive the router that serves the OpenAPI UI.

Adds a route to serve the OAuth2 redirect page.

Parameters:

router – The router that serves the OpenAPI UI.

static render_oauth2_redirect() bytes#

Render an HTML oauth2-redirect.html page for Swagger-UI.

Note

Override this method to customize the template.

Returns:

A rendered html string.

class litestar.openapi.plugins.YamlRenderPlugin#

Bases: OpenAPIRenderPlugin

Render an OpenAPI schema as YAML.

__init__(*, path: str | Sequence[str] = ('/openapi.yaml', '/openapi.yml'), media_type: MediaType | OpenAPIMediaType = OpenAPIMediaType.OPENAPI_YAML, **kwargs: Any) None#

Initialize the OpenAPI UI render plugin.

Parameters:
  • path – Path to serve the OpenAPI UI at.

  • media_type – Media type for the handler.

  • **kwargs – Additional arguments to pass to the base class.

render(request: Request, openapi_schema: dict[str, Any]) bytes#

Render an OpenAPI schema as YAML.

Parameters:
  • request – The request.

  • openapi_schema – The OpenAPI schema as a dictionary.

Returns:

The rendered OpenAPI schema as YAML.