Handler
- class tornado_openapi3.handler.OpenAPIRequestHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs: Any)
Base class for HTTP request handlers.
A request handler extending
tornado.web.RequestHandlerproviding OpenAPI spec validation on incoming requests and translating errors into appropriate HTTP responses.- property spec_dict: dict
The OpenAPI 3 specification
Override this in your request handlers to load or define your OpenAPI 3 spec.
- Return type
- property spec: openapi_core.spec.paths.SpecPath
The OpenAPI 3 specification.
Override this in your request handlers to customize how your OpenAPI 3 spec is loaded and validated.
- Return type
openapi_core.schema.specs.model.Spec
- property custom_formatters: Mapping[str, tornado_openapi3.types.Formatter]
A dictionary mapping value formats to formatter objects.
If your schemas make use of format modifiers, you may specify them in this dictionary paired with a Formatter object that provides methods to validate values and unmarshal them into Python objects.
- Return type
Mapping[str,
Formatter]
- property custom_media_type_deserializers: Mapping[str, Callable[[Union[bytes, str]], Any]]
A dictionary mapping media types to deserializing functions.
If your endpoints make use of content types beyond
application/json, you must add them to this dictionary with a deserializing method that converts the raw body (asbytesorstr) to Python objects.- Return type
Mapping[str,
Deserializer]
- async prepare() None
Called at the beginning of a request before get/post/etc.
Performs OpenAPI validation of the incoming request. Problems encountered while validating the request are translated to HTTP error codes:
OpenAPI Errors
Error Code
Description
PathNotFound404Could not find the path for this request in the OpenAPI specification.
OperationNotFound405Could not find the operation specified for this request in the OpenAPI specification.
CastError,DeserializeError,MissingRequiredParameter,MissingRequestBody,ValidateError400The message body could not be decoded or did not validate against the specified schema.
InvalidSecurity401Required authorization was missing from the request.
MediaTypeNotFound415The content type of the request did not match any of the types in the OpenAPI specification.
Any other
OpenAPIError500An unexpected error occurred.
To provide content in these error requests, you may override
on_openapi_error().