Tornado OpenAPI 3 request and response validation library
Project description
Tornado OpenAPI 3 request and response validation library.
Provides integration between the Tornado web framework and Openapi-core library for validating request and response objects against an OpenAPI 3 specification.
Adding validation to request handlers
from openapi_core import create_spec # type: ignore
from openapi_core.exceptions import OpenAPIError # type: ignore
from openapi_core.deserializing.exceptions import DeserializeError # type: ignore
from openapi_core.schema.media_types.exceptions import ( # type: ignore
InvalidContentType,
)
from openapi_core.unmarshalling.schemas.exceptions import ValidateError # type: ignore
from tornado.web import RequestHandler
from tornado_openapi3.requests import RequestValidator
import yaml
class OpenAPIRequestHandler(RequestHandler):
async def prepare(self) -> None:
maybe_coro = super().prepare()
if maybe_coro and asyncio.iscoroutine(maybe_coro): # pragma: no cover
await maybe_coro
spec = create_spec(yaml.safe_load(self.render_string("openapi.yaml")))
validator = RequestValidator(spec)
result = validator.validate(self.request)
try:
result.raise_for_errors()
except InvalidContentType:
self.set_status(415)
self.finish()
except (DeserializeError, ValidateError) as e:
self.set_status(400)
self.finish()
except OpenAPIError:
raise
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tornado-openapi3-0.1.0.tar.gz
(2.6 kB
view hashes)
Built Distributions
Close
Hashes for tornado_openapi3-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02a66e2305b8c62d3da0c85eacdce2c7eb6a32a84f69e71ec03d56d664afe963 |
|
MD5 | e16d90949fa2fe7b11b3f54a132fa2f7 |
|
BLAKE2b-256 | 203b9c50bb3a4033fc5962de8e8f294bcc9cbe11fa3b8b52272b8e790b888e50 |
Close
Hashes for tornado_openapi3-0.1.0-1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e25602819f6a62d725eab4ae2c19ac90db69fb2f8b8df5835672a9dfaf1ae7a9 |
|
MD5 | 68aeb68e5c5a1ba33eb480b236e67884 |
|
BLAKE2b-256 | ff421c6a8a00c76e81cb8d09b0b69399155cc4023dfce59bed2894c56224908f |