quart_schema.validation module¶
- class quart_schema.validation.DataSource(value)¶
Bases:
enum.Enum
An enumeration.
- FORM = 1¶
- JSON = 2¶
- exception quart_schema.validation.QuerystringValidationError(validation_error: Union[TypeError, pydantic.error_wrappers.ValidationError])¶
- exception quart_schema.validation.RequestHeadersValidationError(validation_error: Union[TypeError, pydantic.error_wrappers.ValidationError])¶
- exception quart_schema.validation.RequestSchemaValidationError(validation_error: Union[TypeError, pydantic.error_wrappers.ValidationError])¶
Bases:
werkzeug.exceptions.BadRequest
- exception quart_schema.validation.ResponseHeadersValidationError(validation_error: Optional[pydantic.error_wrappers.ValidationError] = None)¶
Bases:
quart_schema.validation.ResponseSchemaValidationError
- exception quart_schema.validation.ResponseSchemaValidationError(validation_error: Optional[pydantic.error_wrappers.ValidationError] = None)¶
Bases:
Exception
- exception quart_schema.validation.SchemaInvalidError¶
Bases:
Exception
- quart_schema.validation.validate(*, querystring: Optional[Union[Type[pydantic.main.BaseModel], Type]] = None, request: Optional[Union[Type[pydantic.main.BaseModel], Type]] = None, request_source: quart_schema.validation.DataSource = DataSource.JSON, headers: Optional[Union[Type[pydantic.main.BaseModel], Type]] = None, responses: Dict[int, Tuple[Union[Type[pydantic.main.BaseModel], Type], Optional[Union[Type[pydantic.main.BaseModel], Type]]]]) Callable ¶
Validate the route.
This is a shorthand combination of of the validate_querystring, validate_request, validate_headers, and validate_response decorators. Please see the docstrings for those decorators.
- quart_schema.validation.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.validation.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.validation.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.validation.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.