quart_schema package

Submodules

Module contents

class quart_schema.DataSource(value)

Bases: enum.Enum

An enumeration.

FORM = 1
JSON = 2
class quart_schema.QuartSchema(app: Optional[quart.app.Quart] = None, *, openapi_path: Optional[str] = '/openapi.json', redoc_ui_path: Optional[str] = '/redocs', swagger_ui_path: Optional[str] = '/docs', title: Optional[str] = None, version: str = '0.1.0', tags: Optional[List[quart_schema.typing.TagObject]] = None, convert_casing: bool = False, servers: Optional[List[quart_schema.typing.ServerObject]] = [])

Bases: object

A Quart-Schema instance.

This can be used to initialise Quart-Schema documentation a given app, either directly,

app = Quart(__name__)
QuartSchema(app)

or via the factory pattern,

quart_schema = QuartSchema()

def create_app():
    app = Quart(__name__)
    quart_schema.init_app(app)
    return app

This can be customised using the following arguments,

Parameters
  • openapi_path – The path used to serve the openapi json on, or None to disable documentation.

  • redoc_ui_path – The path used to serve the documentation UI using redoc or None to disable redoc documentation.

  • swagger_ui_path – The path used to serve the documentation UI using swagger or None to disable swagger documentation.

  • title – The publishable title for the app.

  • version – The publishable version for the app.

init_app(app: quart.app.Quart) None
async openapi() dict
async redoc_ui() str
async swagger_ui() str
exception quart_schema.RequestSchemaValidationError(validation_error: Union[TypeError, pydantic.error_wrappers.ValidationError])

Bases: werkzeug.exceptions.BadRequest

exception quart_schema.ResponseSchemaValidationError(validation_error: Optional[pydantic.error_wrappers.ValidationError] = None)

Bases: Exception

exception quart_schema.SchemaValidationError(validation_error: Optional[pydantic.error_wrappers.ValidationError] = None)

Bases: Exception

quart_schema.hide_route(func: Callable) Callable

Mark the func as hidden.

This will prevent the route from being included in the autogenerated documentation.

quart_schema.tag(tags: Iterable[str]) Callable

Add tag names to the route.

This allows for tags to be associated with the route, thereby allowing control over which routes are shown in the documentation.

Parameters

tags – A List (or iterable) or tags to associate.

quart_schema.validate_headers(model_class: Union[Type[pydantic.main.BaseModel], Type]) Callable

Validate the headers.

This ensures that the headers can be converted to the model_class. If they cannot a RequestSchemaValidationError is raised which by default results in a 400 response.

Parameters

model_class – The model to use, either a dataclass, pydantic dataclass or a class that inherits from pydantic’s BaseModel.

quart_schema.validate_querystring(model_class: Union[Type[pydantic.main.BaseModel], Type]) Callable

Validate the querystring arguments.

This ensures that the query string arguments can be converted to the model_class. If they cannot a RequestSchemaValidationError is raised which by default results in a 400 response.

Parameters

model_class – The model to use, either a dataclass, pydantic dataclass or a class that inherits from pydantic’s BaseModel. All the fields must be optional.

quart_schema.validate_request(model_class: Union[Type[pydantic.main.BaseModel], Type], *, source: quart_schema.validation.DataSource = DataSource.JSON) Callable

Validate the request data.

This ensures that the request body is JSON and that the body can be converted to the model_class. If they cannot a RequestSchemaValidationError is raised which by default results in a 400 response.

Parameters
  • model_class – The model to use, either a dataclass, pydantic dataclass or a class that inherits from pydantic’s BaseModel. All the fields must be optional.

  • source – The source of the data to validate (json or form encoded).

quart_schema.validate_response(model_class: Union[Type[pydantic.main.BaseModel], Type], status_code: int = 200, headers_model_class: Optional[Union[Type[pydantic.main.BaseModel], Type]] = None) Callable

Validate the response data.

This ensures that the response is a either dictionary that the body can be converted to the model_class or an instance of the model_class. If this is not possible a ResponseSchemaValidationError is raised which by default results in a 500 response. The returned value is then a dictionary which Quart encodes as JSON.

Parameters
  • model_class – The model to use, either a dataclass, pydantic dataclass or a class that inherits from pydantic’s BaseModel.

  • status_code

    The status code this validation applies

    to. Defaults to 200.

    headers_model_class: The model to use to validate response

    headers, either a dataclass, pydantic dataclass or a class that inherits from pydantic’s BaseModel. Is optional.