connexion.middleware.swagger_ui

Module Contents

Classes

SwaggerUIAPI

Base API class with only minimal behavior related to the specification.

SwaggerUIMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base

Attributes

logger

connexion.middleware.swagger_ui.logger
class connexion.middleware.swagger_ui.SwaggerUIAPI(*args, default: starlette.types.ASGIApp, **kwargs)

Bases: connexion.apis.abstract.AbstractSpecAPI

Base API class with only minimal behavior related to the specification.

Parameters:
  • specification – OpenAPI specification. Can be provided either as dict, or as path to file.

  • base_path – Base path to host the API.

  • resolver – Callable that maps operationID to a function

  • resolver_error_handler – Callable that generates an Operation used for handling ResolveErrors

  • arguments – Jinja arguments to resolve in specification.

  • options – New style options dictionary.

static normalize_string(string)
add_openapi_json(self)

Adds openapi json to {base_path}/openapi.json (or {base_path}/swagger.json for swagger2)

add_openapi_yaml(self)

Adds openapi json to {base_path}/openapi.json (or {base_path}/swagger.json for swagger2)

add_swagger_ui(self)

Adds swagger ui to {base_path}/ui/

class connexion.middleware.swagger_ui.SwaggerUIMiddleware(app: starlette.types.ASGIApp)

Bases: connexion.middleware.AppMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base class

Middleware that hosts a swagger UI.

Parameters:

app – app to wrap in middleware.

__slots__ = []
add_api(self, specification: Union[pathlib.Path, str, dict], base_path: Optional[str] = None, arguments: Optional[dict] = None, **kwargs) None

Add an API to the router based on a OpenAPI spec.

Parameters:
  • specification – OpenAPI spec as dict or path to file.

  • base_path – Base path where to add this API.

  • arguments – Jinja arguments to replace in the spec.

async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None
async default_fn(self, _scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None

Callback to call next app as default when no matching route is found.

Unfortunately we cannot just pass the next app as default, since the router manipulates the scope when descending into mounts, losing information about the base path. Therefore, we use the original scope instead.

This is caused by https://github.com/encode/starlette/issues/1336.