plugins

class litestar.openapi.plugins.OpenAPIRenderPlugin[原始碼]

基底類別: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.

參數:
  • 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.

參數:
  • request -- The request that triggered the render.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

The rendered JSON.

abstractmethod render(request: Request, openapi_schema: dict[str, Any]) bytes[原始碼]

Render the OpenAPI UI.

參數:
  • request -- The request that triggered the render.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

The rendered HTML.

static get_openapi_json_route(request: Request) str[原始碼]

Get the route for the OpenAPI JSON schema.

回傳:

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.

參數:

router -- The router that serves the OpenAPI UI.

has_path(path: str) bool[原始碼]

Check if the plugin has a path.

參數:

path -- The path to check.

回傳:

True if the plugin has the path, False otherwise.

class litestar.openapi.plugins.RapidocRenderPlugin[原始碼]

基底類別: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.

參數:
  • 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.

備註

Override this method to customize the template.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

A rendered html string.

class litestar.openapi.plugins.RedocRenderPlugin[原始碼]

基底類別:OpenAPIRenderPlugin

Render an OpenAPI schema using Redoc.

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

Initialize the OpenAPI UI render plugin.

參數:
  • 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.

備註

override this method to customize the template.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

A rendered html string.

class litestar.openapi.plugins.ScalarRenderPlugin[原始碼]

基底類別:OpenAPIRenderPlugin

Plugin to render an OpenAPI schema using Scalar.

在 2.8.0 版被加入.

__init__(*, version: str = 'latest', js_url: str | None = None, css_url: str | None = None, path: str | Sequence[str] = '/scalar', options: dict[str, Any] | None = None, **kwargs: Any) None[原始碼]

Initialize the Scalar OpenAPI UI render plugin.

參數:
  • 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.

  • options -- Scalar configuration options. If not provided the default Scalar configuration will be used.

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

render(request: Request, openapi_schema: dict[str, Any]) bytes[原始碼]

Render an HTMl page for Scalar.

備註

Override this method to customize the template.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

A rendered html string.

render_options() str[原始碼]

Render options to Scalar configuration.

class litestar.openapi.plugins.StoplightRenderPlugin[原始碼]

基底類別: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.

參數:
  • 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.

備註

Override this method to customize the template.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

A rendered html string.

class litestar.openapi.plugins.SwaggerRenderPlugin[原始碼]

基底類別:OpenAPIRenderPlugin

Render an OpenAPI schema using Swagger-UI.

__init__(version: str = '5.18.2', 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.

參數:
  • 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.

備註

  • override this method to customize the template.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

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.

參數:

router -- The router that serves the OpenAPI UI.

static render_oauth2_redirect() bytes[原始碼]

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

備註

Override this method to customize the template.

回傳:

A rendered html string.

class litestar.openapi.plugins.YamlRenderPlugin[原始碼]

基底類別: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.

參數:
  • 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.

參數:
  • request -- The request.

  • openapi_schema -- The OpenAPI schema as a dictionary.

回傳:

The rendered OpenAPI schema as YAML.