Skip to content

Miscellaneous

pydantictornado.openapi.ValidationError

Bases: BaseModel

Use with register_error_model to document validation errors.

This is the structure of errors returned by handlers.ResponseFormatter. Register this model as the default response for "unprocessable entity" to include it in the generated OpenAPI specification.

class Application(handlers.OpenAPIApplication):
    def __init__(self, **settings: object):
        super().__init__([web.url(r'/items', MyHandler)], **settings)
        self.register_error_model(422, openapi.ValidationError)

Then use it in your handlers that accept a body parameter to specify that they may respond with an "unprocessable entity" error.

class MyHandler(handlers.RequestHandler):
    @api.expose_operation
    @api.add_error_response(422)
    async def post(self, *,
                   body: typing.Annotated[Create, api.Body]) -> MyModel:
        ...

pydantictornado.api.ErrorResponseDefinition

Bases: TypedDict

Keyword parameters to pydantictornado.api.add_error_response.

description instance-attribute

Description of this error response.

model instance-attribute

Model that describes the error response body This parameter overrides the model registered by calling the register_error_model method on the application instance.

pydantictornado.api.ExplicitOpenAPIDocumentation

Bases: TypedDict

Keyword arguments for pydantictornado.api.expose_operation.

This dictionary describes the optional keyword parameters to the api.expose_operation decorator. They are used to populate the OpenAPI specification of the operation with additional information.

default_status instance-attribute

The default status code is 200. This property allows you to override the value that is used if your handler does not set an explicit status code. This is commonly used for DELETE and POST operations where you would use "204 No Content" or "303 See Other" instead of a 200.

description instance-attribute

The default description is the remainder of the docstring after the first line. Use this keyword parameter to explicitly set the description.

operation_id instance-attribute

The default operation ID is generated from the request handler class name and HTTP method name. Use this keyword parameter to set an explicit operation ID.

summary instance-attribute

The default summary is the first line of the method's docstring or the operation ID if no docstring is present. Use this keyword parameter to explicitly set the summary.

tags instance-attribute

Set tags for the operation.

pydantictornado.api.RequestBodyDescription

Bases: TypedDict

Keyword arguments for pydantictornado.api.Body.

description instance-attribute

Description of the request body.

required instance-attribute

Is the request body required?

pydantictornado.api.RequestMethod = typing.Callable[..., typing.Awaitable[None] | None] module-attribute

pydantictornado.api.ResponseHeaderDefinition

Bases: TypedDict

Keyword parameters to pydantictornado.api.add_response_header.

deprecated instance-attribute

Is this header deprecated?

description instance-attribute

Description of the header.

explode instance-attribute

Are multiple values be represented as separate parameters?

Note that the OpenAPI style property is awlays simple for headers. The style examples in OpenAPI 3.1 describe the result of using this parameter.

for_status instance-attribute

Status codes for which this header is returned. If this parameter is omitted, then the header is included for all status codes.

model instance-attribute

Model that describes the header value.

required instance-attribute

Is the header always returned?