starlite.openapi#
- class starlite.openapi.controller.OpenAPIController#
Bases:
ControllerController for OpenAPI endpoints.
- redoc_google_fonts: bool = True#
Download google fonts via CDN.
Should be set to
Falsewhen not using a CDN.
- redoc_js_url: str = 'https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js'#
Download url for the Redoc JS bundle.
- swagger_css_url: str = 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@4.15.5/swagger-ui.css'#
Download url for the Swagger UI CSS bundle.
- swagger_ui_bundle_js_url: str = 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@4.15.5/swagger-ui-bundle.js'#
Download url for the Swagger UI JS bundle.
- swagger_ui_standalone_preset_js_url: str = 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@4.15.5/swagger-ui-standalone-preset.js'#
Download url for the Swagger Standalone Preset JS bundle.
- stoplight_elements_css_url: str = 'https://unpkg.com/@stoplight/elements@7.7.5/styles.min.css'#
Download url for the Stoplight Elements CSS bundle.
- stoplight_elements_js_url: str = 'https://unpkg.com/@stoplight/elements@7.7.5/web-components.min.js'#
Download url for the Stoplight Elements JS bundle.
- static get_schema_from_request(request: Request) OpenAPI#
Return the OpenAPI pydantic model from the request instance.
- Parameters:
request – A
Starliteinstance.- Returns:
An
OpenAPIinstance.- Raises:
ImproperlyConfiguredException – If the application
openapi_configattribute isNone.
- after_request: Optional['AfterRequestHookHandler']#
A sync or async function executed before a
Requestis passed to any route handler.If this function returns a value, the request will not reach the route handler, and instead this value will be used.
- after_response: Optional['AfterResponseHookHandler']#
A sync or async function called after the response has been awaited.
It receives the
Requestinstance and should not return any values.
- before_request: Optional['BeforeRequestHookHandler']#
A sync or async function called immediately before calling the route handler.
It receives the
Requestinstance and any non-Nonereturn value is used for the response, bypassing the route handler.
- dependencies: Optional['Dependencies']#
A string keyed dictionary of dependency
Providerinstances.- Type:
dependencies
- etag: Optional['ETag']#
An
etagheader of typeETagto add to route handlers of this controller.Can be overridden by route handlers.
- exception_handlers: Optional['ExceptionHandlersMap']#
A dictionary that maps handler functions to status codes and/or exception types.
- middleware: Optional[List['Middleware']]#
A list of
Middleware.
- opt: Optional[Dict[str, Any]]#
A string key dictionary of arbitrary values that can be accessed in
Guardsor wherever you have access toRequestorASGI Scope.
- owner: Router#
The
RouterorStarliteapp that owns the controller.This value is set internally by Starlite and it should not be set when subclassing the controller.
- parameters: Optional['ParametersMap']#
A mapping of
Parameterdefinitions available to all application paths.
- response_class: Optional['ResponseType']#
A custom subclass of [starlite.response.Response] to be used as the default response for all route handlers under the controller.
- response_cookies: Optional['ResponseCookies']#
A list of [Cookie](starlite.datastructures.Cookie] instances.
- response_headers: Optional['ResponseHeadersMap']#
A string keyed dictionary mapping
ResponseHeaderinstances.
- security: Optional[List['SecurityRequirement']]#
A list of dictionaries that to the schema of all route handlers under the controller.
- tags: Optional[List[str]]#
A list of string tags that will be appended to the schema of all route handlers under the controller.
- type_encoders: Optional['TypeEncodersMap']#
A mapping of types to callables that transform them into types supported for serialization.
- should_serve_endpoint(request: Request) bool#
Verify that the requested path is within the enabled endpoints in the openapi_config.
- Parameters:
request – To be tested if endpoint enabled.
- Returns:
A boolean.
- Raises:
ImproperlyConfiguredException – If the application
openapi_configattribute isNone.
- property favicon: str#
Return favicon <link> tag, if applicable.
- Returns:
A <link> tag if self.favicon_url is not empty, otherwise returns a placeholder meta tag.
- property render_methods_map: Dict[Literal['redoc', 'swagger', 'elements'], Callable[[Request], str]]#
Map render method names to render methods.
- Returns:
A mapping of string keys to render methods.
- render_swagger_ui(request: Request) str#
Render an HTML page for Swagger-UI.
Notes
override this method to customize the template.
- Parameters:
request – A
Requestinstance.- Returns:
A rendered html string.
- render_stoplight_elements(request: Request) str#
Render an HTML page for StopLight Elements.
Notes
override this method to customize the template.
- Parameters:
request – A
Requestinstance.- Returns:
A rendered html string.
- class starlite.openapi.datastructures.ResponseSpec#
Bases:
BaseModelContainer type of additional responses.