diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 00000000..b8bc4955 --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,5 @@ +API +=== + +.. autosummary:: + :toctree: generated diff --git a/docs/conf.py b/docs/conf.py index fa31b112..cb6623a2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -33,6 +33,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinx.ext.autosummary", "sphinx.ext.doctest", "sphinx.ext.intersphinx", "sphinx.ext.coverage", diff --git a/docs/customizations.rst b/docs/customizations.rst deleted file mode 100644 index a2019fbf..00000000 --- a/docs/customizations.rst +++ /dev/null @@ -1,102 +0,0 @@ -Customizations -============== - -Specification validation ------------------------- - -By default, the specified specification is also validated. - -If you know you have a valid specification already, disabling the validator can improve the performance. - -.. code-block:: python - :emphasize-lines: 1,4,6 - - from openapi_core import Config - - config = Config( - spec_validator_cls=None, - ) - openapi = OpenAPI.from_file_path('openapi.json', config=config) - openapi.validate_request(request) - -Media type deserializers ------------------------- - -OpenAPI comes with a set of built-in media type deserializers such as: ``application/json``, ``application/xml``, ``application/x-www-form-urlencoded`` or ``multipart/form-data``. - -You can also define your own ones. Pass custom defined media type deserializers dictionary with supported mimetypes as a key to `unmarshal_response` function: - -.. code-block:: python - :emphasize-lines: 11 - - def protobuf_deserializer(message): - feature = route_guide_pb2.Feature() - feature.ParseFromString(message) - return feature - - extra_media_type_deserializers = { - 'application/protobuf': protobuf_deserializer, - } - - config = Config( - extra_media_type_deserializers=extra_media_type_deserializers, - ) - openapi = OpenAPI.from_file_path('openapi.json', config=config) - - result = openapi.unmarshal_response(request, response) - -Format validators ------------------ - -OpenAPI defines a ``format`` keyword that hints at how a value should be interpreted, e.g. a ``string`` with the type ``date`` should conform to the RFC 3339 date format. - -OpenAPI comes with a set of built-in format validators, but it's also possible to add custom ones. - -Here's how you could add support for a ``usdate`` format that handles dates of the form MM/DD/YYYY: - -.. code-block:: python - :emphasize-lines: 11 - - import re - - def validate_usdate(value): - return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value)) - - extra_format_validators = { - 'usdate': validate_usdate, - } - - config = Config( - extra_format_validators=extra_format_validators, - ) - openapi = OpenAPI.from_file_path('openapi.json', config=config) - - openapi.validate_response(request, response) - -Format unmarshallers --------------------- - -Based on ``format`` keyword, openapi-core can also unmarshal values to specific formats. - -Openapi-core comes with a set of built-in format unmarshallers, but it's also possible to add custom ones. - -Here's an example with the ``usdate`` format that converts a value to date object: - -.. code-block:: python - :emphasize-lines: 11 - - from datetime import datetime - - def unmarshal_usdate(value): - return datetime.strptime(value, "%m/%d/%y").date - - extra_format_unmarshallers = { - 'usdate': unmarshal_usdate, - } - - config = Config( - extra_format_unmarshallers=extra_format_unmarshallers, - ) - openapi = OpenAPI.from_file_path('openapi.json', config=config) - - result = openapi.unmarshal_response(request, response) diff --git a/docs/customizations/extra_format_unmarshallers.rst b/docs/customizations/extra_format_unmarshallers.rst new file mode 100644 index 00000000..b4d52cca --- /dev/null +++ b/docs/customizations/extra_format_unmarshallers.rst @@ -0,0 +1,27 @@ +Format unmarshallers +==================== + +Based on ``format`` keyword, openapi-core can also unmarshal values to specific formats. + +Openapi-core comes with a set of built-in format unmarshallers, but it's also possible to add custom ones. + +Here's an example with the ``usdate`` format that converts a value to date object: + +.. code-block:: python + :emphasize-lines: 11 + + from datetime import datetime + + def unmarshal_usdate(value): + return datetime.strptime(value, "%m/%d/%y").date + + extra_format_unmarshallers = { + 'usdate': unmarshal_usdate, + } + + config = Config( + extra_format_unmarshallers=extra_format_unmarshallers, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + + result = openapi.unmarshal_response(request, response) diff --git a/docs/customizations/extra_format_validators.rst b/docs/customizations/extra_format_validators.rst new file mode 100644 index 00000000..b984f39e --- /dev/null +++ b/docs/customizations/extra_format_validators.rst @@ -0,0 +1,27 @@ +Format validators +================= + +OpenAPI defines a ``format`` keyword that hints at how a value should be interpreted, e.g. a ``string`` with the type ``date`` should conform to the RFC 3339 date format. + +OpenAPI comes with a set of built-in format validators, but it's also possible to add custom ones. + +Here's how you could add support for a ``usdate`` format that handles dates of the form MM/DD/YYYY: + +.. code-block:: python + :emphasize-lines: 11 + + import re + + def validate_usdate(value): + return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value)) + + extra_format_validators = { + 'usdate': validate_usdate, + } + + config = Config( + extra_format_validators=extra_format_validators, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + + openapi.validate_response(request, response) diff --git a/docs/customizations/extra_media_type_deserializers.rst b/docs/customizations/extra_media_type_deserializers.rst new file mode 100644 index 00000000..02940b5f --- /dev/null +++ b/docs/customizations/extra_media_type_deserializers.rst @@ -0,0 +1,25 @@ +Media type deserializers +======================== + +OpenAPI comes with a set of built-in media type deserializers such as: ``application/json``, ``application/xml``, ``application/x-www-form-urlencoded`` or ``multipart/form-data``. + +You can also define your own ones. Pass custom defined media type deserializers dictionary with supported mimetypes as a key to `unmarshal_response` function: + +.. code-block:: python + :emphasize-lines: 11 + + def protobuf_deserializer(message): + feature = route_guide_pb2.Feature() + feature.ParseFromString(message) + return feature + + extra_media_type_deserializers = { + 'application/protobuf': protobuf_deserializer, + } + + config = Config( + extra_media_type_deserializers=extra_media_type_deserializers, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + + result = openapi.unmarshal_response(request, response) diff --git a/docs/customizations/index.rst b/docs/customizations/index.rst new file mode 100644 index 00000000..b8393abe --- /dev/null +++ b/docs/customizations/index.rst @@ -0,0 +1,16 @@ +Customizations +============== + +OpenAPI accepts ``Config`` object that allows users to customize the behavior validation and unmarshalling processes. + +.. toctree:: + :maxdepth: 1 + + spec_validator_cls + request_validator_cls + response_validator_cls + request_unmarshaller_cls + response_unmarshaller_cls + extra_media_type_deserializers + extra_format_validators + extra_format_unmarshallers diff --git a/docs/customizations/request_unmarshaller_cls.rst b/docs/customizations/request_unmarshaller_cls.rst new file mode 100644 index 00000000..e09ab772 --- /dev/null +++ b/docs/customizations/request_unmarshaller_cls.rst @@ -0,0 +1,22 @@ +Request unmarshaller +==================== + +By default, request unmarshaller is selected based on detected specification version. + +In order to explicitly validate and unmarshal a: + +* OpenAPI 3.0 spec, import ``V30RequestUnmarshaller`` +* OpenAPI 3.1 spec, import ``V31RequestUnmarshaller`` or ``V31WebhookRequestUnmarshaller`` + +.. code-block:: python + :emphasize-lines: 1,4 + + from openapi_core import V31RequestUnmarshaller + + config = Config( + request_unmarshaller_cls=V31RequestUnmarshaller, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + result = openapi.unmarshal_request(request) + +You can also explicitly import ``V3RequestUnmarshaller`` which is a shortcut to the latest OpenAPI v3 version. diff --git a/docs/customizations/request_validator_cls.rst b/docs/customizations/request_validator_cls.rst new file mode 100644 index 00000000..d6dc48b9 --- /dev/null +++ b/docs/customizations/request_validator_cls.rst @@ -0,0 +1,22 @@ +Request validator +================= + +By default, request validator is selected based on detected specification version. + +In order to explicitly validate a: + +* OpenAPI 3.0 spec, import ``V30RequestValidator`` +* OpenAPI 3.1 spec, import ``V31RequestValidator`` or ``V31WebhookRequestValidator`` + +.. code-block:: python + :emphasize-lines: 1,4 + + from openapi_core import V31RequestValidator + + config = Config( + request_validator_cls=V31RequestValidator, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + openapi.validate_request(request) + +You can also explicitly import ``V3RequestValidator`` which is a shortcut to the latest OpenAPI v3 version. diff --git a/docs/customizations/response_unmarshaller_cls.rst b/docs/customizations/response_unmarshaller_cls.rst new file mode 100644 index 00000000..1ccf3997 --- /dev/null +++ b/docs/customizations/response_unmarshaller_cls.rst @@ -0,0 +1,20 @@ +Response unmarshaller +===================== + +In order to explicitly validate and unmarshal a: + +* OpenAPI 3.0 spec, import ``V30ResponseUnmarshaller`` +* OpenAPI 3.1 spec, import ``V31ResponseUnmarshaller`` or ``V31WebhookResponseUnmarshaller`` + +.. code-block:: python + :emphasize-lines: 1,4 + + from openapi_core import V31ResponseUnmarshaller + + config = Config( + response_unmarshaller_cls=V31ResponseUnmarshaller, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + result = openapi.unmarshal_response(request, response) + +You can also explicitly import ``V3ResponseUnmarshaller`` which is a shortcut to the latest OpenAPI v3 version. diff --git a/docs/customizations/response_validator_cls.rst b/docs/customizations/response_validator_cls.rst new file mode 100644 index 00000000..e9249f48 --- /dev/null +++ b/docs/customizations/response_validator_cls.rst @@ -0,0 +1,22 @@ +Response validator +================== + +By default, response validator is selected based on detected specification version. + +In order to explicitly validate a: + +* OpenAPI 3.0 spec, import ``V30ResponseValidator`` +* OpenAPI 3.1 spec, import ``V31ResponseValidator`` or ``V31WebhookResponseValidator`` + +.. code-block:: python + :emphasize-lines: 1,4 + + from openapi_core import V31ResponseValidator + + config = Config( + response_validator_cls=V31ResponseValidator, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) + openapi.validate_response(request, response) + +You can also explicitly import ``V3ResponseValidator`` which is a shortcut to the latest OpenAPI v3 version. diff --git a/docs/customizations/spec_validator_cls.rst b/docs/customizations/spec_validator_cls.rst new file mode 100644 index 00000000..0b912af7 --- /dev/null +++ b/docs/customizations/spec_validator_cls.rst @@ -0,0 +1,16 @@ +Specification validation +======================== + +By default, on OpenAPI creation time, the provided specification is also validated. + +If you know you have a valid specification already, disabling the validator can improve the performance. + +.. code-block:: python + :emphasize-lines: 1,4,6 + + from openapi_core import Config + + config = Config( + spec_validator_cls=None, + ) + openapi = OpenAPI.from_file_path('openapi.json', config=config) diff --git a/docs/extensions.rst b/docs/extensions.rst index eaa3bf85..b93e95c9 100644 --- a/docs/extensions.rst +++ b/docs/extensions.rst @@ -9,7 +9,7 @@ By default, objects are unmarshalled to dictionaries. You can use dynamically cr .. code-block:: yaml :emphasize-lines: 5 - ... + # ... components: schemas: Coordinates: diff --git a/docs/index.rst b/docs/index.rst index f2defc02..37b0cd58 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,15 +3,16 @@ openapi-core .. toctree:: :hidden: - :maxdepth: 2 + :maxdepth: 3 unmarshalling validation - integrations - customizations + integrations/index + customizations/index security extensions contributing + api Openapi-core is a Python library that adds client-side and server-side support for the `OpenAPI v3.0 `__ @@ -21,8 +22,8 @@ Key features ------------ * :doc:`validation` and :doc:`unmarshalling ` of request and response data (including webhooks) -* :doc:`Integrations ` with popular libraries (Requests, Werkzeug) and frameworks (Django, Falcon, Flask, Starlette) -* :doc:`Customization ` with **media type deserializers** and **format unmarshallers** +* :doc:`Integrations ` with popular libraries (Requests, Werkzeug) and frameworks (Django, Falcon, Flask, Starlette) +* :doc:`Customization ` with **media type deserializers** and **format unmarshallers** * :doc:`Security ` data providers (API keys, Cookie, Basic and Bearer HTTP authentications) Installation @@ -74,7 +75,7 @@ Retrieve validated and unmarshalled request data # get security data security = result.security -Request object should implement OpenAPI Request protocol. Check :doc:`integrations` to find oficially supported implementations. +Request object should implement OpenAPI Request protocol. Check :doc:`integrations/index` to find oficially supported implementations. For more details read about :doc:`unmarshalling` process. diff --git a/docs/integrations.rst b/docs/integrations.rst deleted file mode 100644 index c20247c1..00000000 --- a/docs/integrations.rst +++ /dev/null @@ -1,512 +0,0 @@ -Integrations -============ - -Openapi-core integrates with your popular libraries and frameworks. Each integration offers different levels of integration that help validate and unmarshal your request and response data. - -aiohttp.web ------------ - -This section describes integration with `aiohttp.web `__ framework. - -Low level -~~~~~~~~~ - -You can use ``AIOHTTPOpenAPIWebRequest`` as an aiohttp request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.aiohttp import AIOHTTPOpenAPIWebRequest - - request_body = await aiohttp_request.text() - openapi_request = AIOHTTPOpenAPIWebRequest(aiohttp_request, body=request_body) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``AIOHTTPOpenAPIWebRequest`` as an aiohttp response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.starlette import AIOHTTPOpenAPIWebRequest - - openapi_response = StarletteOpenAPIResponse(aiohttp_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) - - -Bottle ------- - -See `bottle-openapi-3 `_ project. - - -Django ------- - -This section describes integration with `Django `__ web framework. -The integration supports Django from version 3.0 and above. - -Middleware -~~~~~~~~~~ - -Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your ``MIDDLEWARE`` list and define ``OPENAPI``. - -.. code-block:: python - :emphasize-lines: 6,9 - - # settings.py - from openapi_core import OpenAPI - - MIDDLEWARE = [ - # ... - 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', - ] - - OPENAPI = OpenAPI.from_dict(spec_dict) - -You can skip response validation process: by setting ``OPENAPI_RESPONSE_CLS`` to ``None`` - -.. code-block:: python - :emphasize-lines: 10 - - # settings.py - from openapi_core import OpenAPI - - MIDDLEWARE = [ - # ... - 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', - ] - - OPENAPI = OpenAPI.from_dict(spec_dict) - OPENAPI_RESPONSE_CLS = None - -After that you have access to unmarshal result object with all validated request data from Django view through request object. - -.. code-block:: python - - from django.views import View - - class MyView(View): - def get(self, req): - # get parameters object with path, query, cookies and headers parameters - validated_params = req.openapi.parameters - # or specific location parameters - validated_path_params = req.openapi.parameters.path - - # get body - validated_body = req.openapi.body - - # get security data - validated_security = req.openapi.security - -Low level -~~~~~~~~~ - -You can use ``DjangoOpenAPIRequest`` as a Django request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.django import DjangoOpenAPIRequest - - openapi_request = DjangoOpenAPIRequest(django_request) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``DjangoOpenAPIResponse`` as a Django response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.django import DjangoOpenAPIResponse - - openapi_response = DjangoOpenAPIResponse(django_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) - - -Falcon ------- - -This section describes integration with `Falcon `__ web framework. -The integration supports Falcon from version 3.0 and above. - -Middleware -~~~~~~~~~~ - -The Falcon API can be integrated by ``FalconOpenAPIMiddleware`` middleware. - -.. code-block:: python - :emphasize-lines: 1,3,7 - - from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware - - openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec) - - app = falcon.App( - # ... - middleware=[openapi_middleware], - ) - -Additional customization parameters can be passed to the middleware. - -.. code-block:: python - :emphasize-lines: 5 - - from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware - - openapi_middleware = FalconOpenAPIMiddleware.from_spec( - spec, - extra_format_validators=extra_format_validators, - ) - - app = falcon.App( - # ... - middleware=[openapi_middleware], - ) - -You can skip response validation process: by setting ``response_cls`` to ``None`` - -.. code-block:: python - :emphasize-lines: 5 - - from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware - - openapi_middleware = FalconOpenAPIMiddleware.from_spec( - spec, - response_cls=None, - ) - - app = falcon.App( - # ... - middleware=[openapi_middleware], - ) - -After that you will have access to validation result object with all validated request data from Falcon view through request context. - -.. code-block:: python - - class ThingsResource: - def on_get(self, req, resp): - # get parameters object with path, query, cookies and headers parameters - validated_params = req.context.openapi.parameters - # or specific location parameters - validated_path_params = req.context.openapi.parameters.path - - # get body - validated_body = req.context.openapi.body - - # get security data - validated_security = req.context.openapi.security - -Low level -~~~~~~~~~ - -You can use ``FalconOpenAPIRequest`` as a Falcon request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.falcon import FalconOpenAPIRequest - - openapi_request = FalconOpenAPIRequest(falcon_request) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``FalconOpenAPIResponse`` as a Falcon response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.falcon import FalconOpenAPIResponse - - openapi_response = FalconOpenAPIResponse(falcon_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) - - -Flask ------ - -This section describes integration with `Flask `__ web framework. - -Decorator -~~~~~~~~~ - -Flask views can be integrated by ``FlaskOpenAPIViewDecorator`` decorator. - -.. code-block:: python - :emphasize-lines: 1,3,6 - - from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator - - openapi = FlaskOpenAPIViewDecorator.from_spec(spec) - - @app.route('/home') - @openapi - def home(): - return "Welcome home" - -Additional customization parameters can be passed to the decorator. - -.. code-block:: python - :emphasize-lines: 5 - - from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator - - openapi = FlaskOpenAPIViewDecorator.from_spec( - spec, - extra_format_validators=extra_format_validators, - ) - -You can skip response validation process: by setting ``response_cls`` to ``None`` - -.. code-block:: python - :emphasize-lines: 5 - - from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator - - openapi = FlaskOpenAPIViewDecorator.from_spec( - spec, - response_cls=None, - ) - -If you want to decorate class based view you can use the decorators attribute: - -.. code-block:: python - :emphasize-lines: 2 - - class MyView(View): - decorators = [openapi] - - def dispatch_request(self): - return "Welcome home" - - app.add_url_rule('/home', view_func=MyView.as_view('home')) - -View -~~~~ - -As an alternative to the decorator-based integration, a Flask method based views can be integrated by inheritance from ``FlaskOpenAPIView`` class. - -.. code-block:: python - :emphasize-lines: 1,3,8 - - from openapi_core.contrib.flask.views import FlaskOpenAPIView - - class MyView(FlaskOpenAPIView): - def get(self): - return "Welcome home" - - app.add_url_rule( - '/home', - view_func=MyView.as_view('home', spec), - ) - -Additional customization parameters can be passed to the view. - -.. code-block:: python - :emphasize-lines: 10 - - from openapi_core.contrib.flask.views import FlaskOpenAPIView - - class MyView(FlaskOpenAPIView): - def get(self): - return "Welcome home" - - app.add_url_rule( - '/home', - view_func=MyView.as_view( - 'home', spec, - extra_format_validators=extra_format_validators, - ), - ) - -Request parameters -~~~~~~~~~~~~~~~~~~ - -In Flask, all unmarshalled request data are provided as Flask request object's ``openapi.parameters`` attribute - -.. code-block:: python - :emphasize-lines: 6,7 - - from flask.globals import request - - @app.route('/browse//') - @openapi - def browse(id): - browse_id = request.openapi.parameters.path['id'] - page = request.openapi.parameters.query.get('page', 1) - - return f"Browse {browse_id}, page {page}" - -Low level -~~~~~~~~~ - -You can use ``FlaskOpenAPIRequest`` as a Flask request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.flask import FlaskOpenAPIRequest - - openapi_request = FlaskOpenAPIRequest(flask_request) - result = unmarshal_request(openapi_request, spec=spec) - -For response factory see `Werkzeug`_ integration. - - -Pyramid -------- - -See `pyramid_openapi3 `_ project. - - -Requests --------- - -This section describes integration with `Requests `__ library. - -Low level -~~~~~~~~~ - -You can use ``RequestsOpenAPIRequest`` as a Requests request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.requests import RequestsOpenAPIRequest - - openapi_request = RequestsOpenAPIRequest(requests_request) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``RequestsOpenAPIResponse`` as a Requests response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.requests import RequestsOpenAPIResponse - - openapi_response = RequestsOpenAPIResponse(requests_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) - - -You can use ``RequestsOpenAPIWebhookRequest`` as a Requests webhook request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.requests import RequestsOpenAPIWebhookRequest - - openapi_webhook_request = RequestsOpenAPIWebhookRequest(requests_request, "my_webhook") - result = unmarshal_request(openapi_webhook_request, spec=spec) - - -Starlette ---------- - -This section describes integration with `Starlette `__ ASGI framework. - -Middleware -~~~~~~~~~~ - -Starlette can be integrated by middleware. Add ``StarletteOpenAPIMiddleware`` with ``spec`` to your ``middleware`` list. - -.. code-block:: python - :emphasize-lines: 1,6 - - from openapi_core.contrib.starlette.middlewares import StarletteOpenAPIMiddleware - from starlette.applications import Starlette - from starlette.middleware import Middleware - - middleware = [ - Middleware(StarletteOpenAPIMiddleware, spec=spec), - ] - - app = Starlette( - # ... - middleware=middleware, - ) - -After that you have access to unmarshal result object with all validated request data from endpoint through ``openapi`` key of request's scope directory. - -.. code-block:: python - - async def get_endpoint(req): - # get parameters object with path, query, cookies and headers parameters - validated_params = req.scope["openapi"].parameters - # or specific location parameters - validated_path_params = req.scope["openapi"].parameters.path - - # get body - validated_body = req.scope["openapi"].body - - # get security data - validated_security = req.scope["openapi"].security - -You can skip response validation process: by setting ``response_cls`` to ``None`` - -.. code-block:: python - :emphasize-lines: 2 - - middleware = [ - Middleware(StarletteOpenAPIMiddleware, spec=spec, response_cls=None), - ] - - app = Starlette( - # ... - middleware=middleware, - ) - -Low level -~~~~~~~~~ - -You can use ``StarletteOpenAPIRequest`` as a Starlette request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.starlette import StarletteOpenAPIRequest - - openapi_request = StarletteOpenAPIRequest(starlette_request) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``StarletteOpenAPIResponse`` as a Starlette response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.starlette import StarletteOpenAPIResponse - - openapi_response = StarletteOpenAPIResponse(starlette_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) - - -Tornado -------- - -See `tornado-openapi3 `_ project. - - -Werkzeug --------- - -This section describes integration with `Werkzeug `__ a WSGI web application library. - -Low level -~~~~~~~~~ - -You can use ``WerkzeugOpenAPIRequest`` as a Werkzeug request factory: - -.. code-block:: python - - from openapi_core import unmarshal_request - from openapi_core.contrib.werkzeug import WerkzeugOpenAPIRequest - - openapi_request = WerkzeugOpenAPIRequest(werkzeug_request) - result = unmarshal_request(openapi_request, spec=spec) - -You can use ``WerkzeugOpenAPIResponse`` as a Werkzeug response factory: - -.. code-block:: python - - from openapi_core import unmarshal_response - from openapi_core.contrib.werkzeug import WerkzeugOpenAPIResponse - - openapi_response = WerkzeugOpenAPIResponse(werkzeug_response) - result = unmarshal_response(openapi_request, openapi_response, spec=spec) diff --git a/docs/integrations/aiohttp.rst b/docs/integrations/aiohttp.rst new file mode 100644 index 00000000..455771ec --- /dev/null +++ b/docs/integrations/aiohttp.rst @@ -0,0 +1,26 @@ +aiohttp.web +=========== + +This section describes integration with `aiohttp.web `__ framework. + +Low level +--------- + +You can use ``AIOHTTPOpenAPIWebRequest`` as an aiohttp request factory: + +.. code-block:: python + + from openapi_core.contrib.aiohttp import AIOHTTPOpenAPIWebRequest + + request_body = await aiohttp_request.text() + openapi_request = AIOHTTPOpenAPIWebRequest(aiohttp_request, body=request_body) + result = openapi.unmarshal_request(openapi_request) + +You can use ``AIOHTTPOpenAPIWebRequest`` as an aiohttp response factory: + +.. code-block:: python + + from openapi_core.contrib.starlette import AIOHTTPOpenAPIWebRequest + + openapi_response = StarletteOpenAPIResponse(aiohttp_response) + result = openapi.unmarshal_response(openapi_request, openapi_response) diff --git a/docs/integrations/bottle.rst b/docs/integrations/bottle.rst new file mode 100644 index 00000000..5dd7f737 --- /dev/null +++ b/docs/integrations/bottle.rst @@ -0,0 +1,4 @@ +Bottle +====== + +See `bottle-openapi-3 `_ project. diff --git a/docs/integrations/django.rst b/docs/integrations/django.rst new file mode 100644 index 00000000..1907ed0e --- /dev/null +++ b/docs/integrations/django.rst @@ -0,0 +1,80 @@ +Django +====== + +This section describes integration with `Django `__ web framework. +The integration supports Django from version 3.0 and above. + +Middleware +---------- + +Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your ``MIDDLEWARE`` list and define ``OPENAPI``. + +.. code-block:: python + :emphasize-lines: 6,9 + + # settings.py + from openapi_core import OpenAPI + + MIDDLEWARE = [ + # ... + 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', + ] + + OPENAPI = OpenAPI.from_dict(spec_dict) + +You can skip response validation process: by setting ``OPENAPI_RESPONSE_CLS`` to ``None`` + +.. code-block:: python + :emphasize-lines: 10 + + # settings.py + from openapi_core import OpenAPI + + MIDDLEWARE = [ + # ... + 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', + ] + + OPENAPI = OpenAPI.from_dict(spec_dict) + OPENAPI_RESPONSE_CLS = None + +After that you have access to unmarshal result object with all validated request data from Django view through request object. + +.. code-block:: python + + from django.views import View + + class MyView(View): + def get(self, req): + # get parameters object with path, query, cookies and headers parameters + validated_params = req.openapi.parameters + # or specific location parameters + validated_path_params = req.openapi.parameters.path + + # get body + validated_body = req.openapi.body + + # get security data + validated_security = req.openapi.security + +Low level +--------- + +You can use ``DjangoOpenAPIRequest`` as a Django request factory: + +.. code-block:: python + + from openapi_core.contrib.django import DjangoOpenAPIRequest + + openapi_request = DjangoOpenAPIRequest(django_request) + result = openapi.unmarshal_request(openapi_request) + +You can use ``DjangoOpenAPIResponse`` as a Django response factory: + +.. code-block:: python + + from openapi_core.contrib.django import DjangoOpenAPIResponse + + openapi_response = DjangoOpenAPIResponse(django_response) + result = openapi.unmarshal_response(openapi_request, openapi_response) + diff --git a/docs/integrations/falcon.rst b/docs/integrations/falcon.rst new file mode 100644 index 00000000..78f95c0e --- /dev/null +++ b/docs/integrations/falcon.rst @@ -0,0 +1,94 @@ +Falcon +====== + +This section describes integration with `Falcon `__ web framework. +The integration supports Falcon from version 3.0 and above. + +Middleware +---------- + +The Falcon API can be integrated by ``FalconOpenAPIMiddleware`` middleware. + +.. code-block:: python + :emphasize-lines: 1,3,7 + + from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware + + openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec) + + app = falcon.App( + # ... + middleware=[openapi_middleware], + ) + +Additional customization parameters can be passed to the middleware. + +.. code-block:: python + :emphasize-lines: 5 + + from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware + + openapi_middleware = FalconOpenAPIMiddleware.from_spec( + spec, + extra_format_validators=extra_format_validators, + ) + + app = falcon.App( + # ... + middleware=[openapi_middleware], + ) + +You can skip response validation process: by setting ``response_cls`` to ``None`` + +.. code-block:: python + :emphasize-lines: 5 + + from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware + + openapi_middleware = FalconOpenAPIMiddleware.from_spec( + spec, + response_cls=None, + ) + + app = falcon.App( + # ... + middleware=[openapi_middleware], + ) + +After that you will have access to validation result object with all validated request data from Falcon view through request context. + +.. code-block:: python + + class ThingsResource: + def on_get(self, req, resp): + # get parameters object with path, query, cookies and headers parameters + validated_params = req.context.openapi.parameters + # or specific location parameters + validated_path_params = req.context.openapi.parameters.path + + # get body + validated_body = req.context.openapi.body + + # get security data + validated_security = req.context.openapi.security + +Low level +--------- + +You can use ``FalconOpenAPIRequest`` as a Falcon request factory: + +.. code-block:: python + + from openapi_core.contrib.falcon import FalconOpenAPIRequest + + openapi_request = FalconOpenAPIRequest(falcon_request) + result = openapi.unmarshal_request(openapi_request) + +You can use ``FalconOpenAPIResponse`` as a Falcon response factory: + +.. code-block:: python + + from openapi_core.contrib.falcon import FalconOpenAPIResponse + + openapi_response = FalconOpenAPIResponse(falcon_response) + result = openapi.unmarshal_response(openapi_request, openapi_response) diff --git a/docs/integrations/flask.rst b/docs/integrations/flask.rst new file mode 100644 index 00000000..0a2e88bc --- /dev/null +++ b/docs/integrations/flask.rst @@ -0,0 +1,128 @@ +Flask +====== + +This section describes integration with `Flask `__ web framework. + +Decorator +--------- + +Flask views can be integrated by ``FlaskOpenAPIViewDecorator`` decorator. + +.. code-block:: python + :emphasize-lines: 1,3,6 + + from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator + + openapi = FlaskOpenAPIViewDecorator.from_spec(spec) + + @app.route('/home') + @openapi + def home(): + return "Welcome home" + +Additional customization parameters can be passed to the decorator. + +.. code-block:: python + :emphasize-lines: 5 + + from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator + + openapi = FlaskOpenAPIViewDecorator.from_spec( + spec, + extra_format_validators=extra_format_validators, + ) + +You can skip response validation process: by setting ``response_cls`` to ``None`` + +.. code-block:: python + :emphasize-lines: 5 + + from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator + + openapi = FlaskOpenAPIViewDecorator.from_spec( + spec, + response_cls=None, + ) + +If you want to decorate class based view you can use the decorators attribute: + +.. code-block:: python + :emphasize-lines: 2 + + class MyView(View): + decorators = [openapi] + + def dispatch_request(self): + return "Welcome home" + + app.add_url_rule('/home', view_func=MyView.as_view('home')) + +View +---- + +As an alternative to the decorator-based integration, a Flask method based views can be integrated by inheritance from ``FlaskOpenAPIView`` class. + +.. code-block:: python + :emphasize-lines: 1,3,8 + + from openapi_core.contrib.flask.views import FlaskOpenAPIView + + class MyView(FlaskOpenAPIView): + def get(self): + return "Welcome home" + + app.add_url_rule( + '/home', + view_func=MyView.as_view('home', spec), + ) + +Additional customization parameters can be passed to the view. + +.. code-block:: python + :emphasize-lines: 10 + + from openapi_core.contrib.flask.views import FlaskOpenAPIView + + class MyView(FlaskOpenAPIView): + def get(self): + return "Welcome home" + + app.add_url_rule( + '/home', + view_func=MyView.as_view( + 'home', spec, + extra_format_validators=extra_format_validators, + ), + ) + +Request parameters +------------------ + +In Flask, all unmarshalled request data are provided as Flask request object's ``openapi.parameters`` attribute + +.. code-block:: python + :emphasize-lines: 6,7 + + from flask.globals import request + + @app.route('/browse//') + @openapi + def browse(id): + browse_id = request.openapi.parameters.path['id'] + page = request.openapi.parameters.query.get('page', 1) + + return f"Browse {browse_id}, page {page}" + +Low level +--------- + +You can use ``FlaskOpenAPIRequest`` as a Flask request factory: + +.. code-block:: python + + from openapi_core.contrib.flask import FlaskOpenAPIRequest + + openapi_request = FlaskOpenAPIRequest(flask_request) + result = openapi.unmarshal_request(openapi_request) + +For response factory see `Werkzeug `_ integration. diff --git a/docs/integrations/index.rst b/docs/integrations/index.rst new file mode 100644 index 00000000..cd046758 --- /dev/null +++ b/docs/integrations/index.rst @@ -0,0 +1,18 @@ +Integrations +============ + +Openapi-core integrates with your popular libraries and frameworks. Each integration offers different levels of integration that help validate and unmarshal your request and response data. + +.. toctree:: + :maxdepth: 1 + + aiohttp + bottle + django + falcon + flask + pyramid + requests + starlette + tornado + werkzeug diff --git a/docs/integrations/pyramid.rst b/docs/integrations/pyramid.rst new file mode 100644 index 00000000..6989c5ce --- /dev/null +++ b/docs/integrations/pyramid.rst @@ -0,0 +1,4 @@ +Pyramid +======= + +See `pyramid_openapi3 `_ project. diff --git a/docs/integrations/requests.rst b/docs/integrations/requests.rst new file mode 100644 index 00000000..c6ae39f2 --- /dev/null +++ b/docs/integrations/requests.rst @@ -0,0 +1,35 @@ +Requests +======== + +This section describes integration with `Requests `__ library. + +Low level +--------- + +You can use ``RequestsOpenAPIRequest`` as a Requests request factory: + +.. code-block:: python + + from openapi_core.contrib.requests import RequestsOpenAPIRequest + + openapi_request = RequestsOpenAPIRequest(requests_request) + result = openapi.unmarshal_request(openapi_request) + +You can use ``RequestsOpenAPIResponse`` as a Requests response factory: + +.. code-block:: python + + from openapi_core.contrib.requests import RequestsOpenAPIResponse + + openapi_response = RequestsOpenAPIResponse(requests_response) + result = openapi.unmarshal_response(openapi_request, openapi_response) + + +You can use ``RequestsOpenAPIWebhookRequest`` as a Requests webhook request factory: + +.. code-block:: python + + from openapi_core.contrib.requests import RequestsOpenAPIWebhookRequest + + openapi_webhook_request = RequestsOpenAPIWebhookRequest(requests_request, "my_webhook") + result = openapi.unmarshal_request(openapi_webhook_request) diff --git a/docs/integrations/starlette.rst b/docs/integrations/starlette.rst new file mode 100644 index 00000000..bc4bd3a0 --- /dev/null +++ b/docs/integrations/starlette.rst @@ -0,0 +1,76 @@ +Starlette +========= + +This section describes integration with `Starlette `__ ASGI framework. + +Middleware +---------- + +Starlette can be integrated by middleware. Add ``StarletteOpenAPIMiddleware`` with ``spec`` to your ``middleware`` list. + +.. code-block:: python + :emphasize-lines: 1,6 + + from openapi_core.contrib.starlette.middlewares import StarletteOpenAPIMiddleware + from starlette.applications import Starlette + from starlette.middleware import Middleware + + middleware = [ + Middleware(StarletteOpenAPIMiddleware, openapi=openapi), + ] + + app = Starlette( + # ... + middleware=middleware, + ) + +After that you have access to unmarshal result object with all validated request data from endpoint through ``openapi`` key of request's scope directory. + +.. code-block:: python + + async def get_endpoint(req): + # get parameters object with path, query, cookies and headers parameters + validated_params = req.scope["openapi"].parameters + # or specific location parameters + validated_path_params = req.scope["openapi"].parameters.path + + # get body + validated_body = req.scope["openapi"].body + + # get security data + validated_security = req.scope["openapi"].security + +You can skip response validation process: by setting ``response_cls`` to ``None`` + +.. code-block:: python + :emphasize-lines: 2 + + middleware = [ + Middleware(StarletteOpenAPIMiddleware, openapi=openapi, response_cls=None), + ] + + app = Starlette( + # ... + middleware=middleware, + ) + +Low level +--------- + +You can use ``StarletteOpenAPIRequest`` as a Starlette request factory: + +.. code-block:: python + + from openapi_core.contrib.starlette import StarletteOpenAPIRequest + + openapi_request = StarletteOpenAPIRequest(starlette_request) + result = openapi.unmarshal_request(openapi_request) + +You can use ``StarletteOpenAPIResponse`` as a Starlette response factory: + +.. code-block:: python + + from openapi_core.contrib.starlette import StarletteOpenAPIResponse + + openapi_response = StarletteOpenAPIResponse(starlette_response) + result = openapi.unmarshal_response(openapi_request, openapi_response) diff --git a/docs/integrations/tornado.rst b/docs/integrations/tornado.rst new file mode 100644 index 00000000..59ace988 --- /dev/null +++ b/docs/integrations/tornado.rst @@ -0,0 +1,4 @@ +Tornado +======= + +See `tornado-openapi3 `_ project. diff --git a/docs/integrations/werkzeug.rst b/docs/integrations/werkzeug.rst new file mode 100644 index 00000000..8136ff81 --- /dev/null +++ b/docs/integrations/werkzeug.rst @@ -0,0 +1,33 @@ +Werkzeug +======== + +This section describes integration with `Werkzeug `__ a WSGI web application library. + +Low level +--------- + +The integration defines ``WerkzeugOpenAPIRequest`` and ``WerkzeugOpenAPIResponse`` classes that convert +Werkzeug requests and responses to OpenAPI ones. + +.. md-tab-set:: + + .. md-tab-item:: Request + + .. code-block:: python + + from openapi_core.contrib.werkzeug import WerkzeugOpenAPIRequest + + openapi_request = WerkzeugOpenAPIRequest(werkzeug_request) + + result = openapi.unmarshal_request(openapi_request) + + .. md-tab-item:: Response + + .. code-block:: python + + from openapi_core.contrib.werkzeug import WerkzeugOpenAPIRequest, WerkzeugOpenAPIResponse + + openapi_request = WerkzeugOpenAPIRequest(werkzeug_request) + openapi_response = WerkzeugOpenAPIResponse(werkzeug_response) + + result = openapi.unmarshal_response(openapi_request, openapi_response) diff --git a/docs/unmarshalling.rst b/docs/unmarshalling.rst index 5a7eb17b..82c1302b 100644 --- a/docs/unmarshalling.rst +++ b/docs/unmarshalling.rst @@ -13,34 +13,32 @@ Openapi-core comes with a set of built-in format unmarshallers: * ``uuid`` - converts string into an UUID object, * ``byte`` - decodes Base64-encoded string. -You can also define your own format unmarshallers (See :doc:`customizations`). +You can also define your own format unmarshallers (See :doc:`customizations/extra_format_unmarshallers`). Request unmarshalling --------------------- -Use ``unmarshal_request`` function to validate and unmarshal request data against a given spec. By default, OpenAPI spec version is detected: +Use ``unmarshal_request`` method to validate and unmarshal request data against a given spec. By default, OpenAPI spec version is detected: .. code-block:: python - from openapi_core import unmarshal_request - # raises error if request is invalid - result = unmarshal_request(request, spec=spec) + result = openapi.unmarshal_request(request) -Request object should implement OpenAPI Request protocol (See :doc:`integrations`). +Request object should implement OpenAPI Request protocol (See :doc:`integrations/index`). .. note:: Webhooks feature is part of OpenAPI v3.1 only -Use the same function to validate and unmarshal webhook request data against a given spec. +Use the same method to validate and unmarshal webhook request data against a given spec. .. code-block:: python # raises error if request is invalid - result = unmarshal_request(webhook_request, spec=spec) + result = openapi.unmarshal_request(webhook_request) -Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations`). +Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations/index`). Retrieve validated and unmarshalled request data @@ -56,48 +54,30 @@ Retrieve validated and unmarshalled request data # get security data security = result.security -In order to explicitly validate and unmarshal a: - -* OpenAPI 3.0 spec, import ``V30RequestUnmarshaller`` -* OpenAPI 3.1 spec, import ``V31RequestUnmarshaller`` or ``V31WebhookRequestUnmarshaller`` - -.. code-block:: python - :emphasize-lines: 1,6 - - from openapi_core import V31RequestUnmarshaller - - result = unmarshal_request( - request, response, - spec=spec, - cls=V31RequestUnmarshaller, - ) - -You can also explicitly import ``V3RequestUnmarshaller`` which is a shortcut to the latest OpenAPI v3 version. +You can also define your own request unmarshaller (See :doc:`customizations/request_unmarshaller_cls`). Response unmarshalling ---------------------- -Use ``unmarshal_response`` function to validate and unmarshal response data against a given spec. By default, OpenAPI spec version is detected: +Use ``unmarshal_response`` method to validate and unmarshal response data against a given spec. By default, OpenAPI spec version is detected: .. code-block:: python - from openapi_core import unmarshal_response - # raises error if response is invalid - result = unmarshal_response(request, response, spec=spec) + result = openapi.unmarshal_response(request, response) -Response object should implement OpenAPI Response protocol (See :doc:`integrations`). +Response object should implement OpenAPI Response protocol (See :doc:`integrations/index`). .. note:: Webhooks feature is part of OpenAPI v3.1 only -Use the same function to validate and unmarshal response data from webhook request against a given spec. +Use the same method to validate and unmarshal response data from webhook request against a given spec. .. code-block:: python # raises error if request is invalid - result = unmarshal_response(webhook_request, response, spec=spec) + result = openapi.unmarshal_response(webhook_request, response) Retrieve validated and unmarshalled response data @@ -108,20 +88,4 @@ Retrieve validated and unmarshalled response data # get data data = result.data -In order to explicitly validate and unmarshal a: - -* OpenAPI 3.0 spec, import ``V30ResponseUnmarshaller`` -* OpenAPI 3.1 spec, import ``V31ResponseUnmarshaller`` or ``V31WebhookResponseUnmarshaller`` - -.. code-block:: python - :emphasize-lines: 1,6 - - from openapi_core import V31ResponseUnmarshaller - - result = unmarshal_response( - request, response, - spec=spec, - cls=V31ResponseUnmarshaller, - ) - -You can also explicitly import ``V3ResponseUnmarshaller`` which is a shortcut to the latest OpenAPI v3 version. +You can also define your own response unmarshaller (See :doc:`customizations/response_unmarshaller_cls`). diff --git a/docs/validation.rst b/docs/validation.rst index 829c28c2..0cd9ac22 100644 --- a/docs/validation.rst +++ b/docs/validation.rst @@ -9,52 +9,34 @@ Such valid formats can be forther unmarshalled (See :doc:`unmarshalling`). Depends on the OpenAPI version, openapi-core comes with a set of built-in format validators such as: ``date``, ``date-time``, ``binary``, ``uuid`` or ``byte``. -You can also define your own format validators (See :doc:`customizations`). +You can also define your own format validators (See :doc:`customizations/extra_format_validators`). Request validation ------------------ -Use ``validate_request`` function to validate request data against a given spec. By default, OpenAPI spec version is detected: +Use ``validate_request`` method to validate request data against a given spec. By default, OpenAPI spec version is detected: .. code-block:: python - from openapi_core import validate_request - # raises error if request is invalid - validate_request(request, spec=spec) + openapi.validate_request(request) -Request object should implement OpenAPI Request protocol (See :doc:`integrations`). +Request object should implement OpenAPI Request protocol (See :doc:`integrations/index`). .. note:: Webhooks feature is part of OpenAPI v3.1 only -Use the same function to validate webhook request data against a given spec. +Use the same method to validate webhook request data against a given spec. .. code-block:: python # raises error if request is invalid - validate_request(webhook_request, spec=spec) - -Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations`). - -In order to explicitly validate and unmarshal a: - -* OpenAPI 3.0 spec, import ``V30RequestValidator`` -* OpenAPI 3.1 spec, import ``V31RequestValidator`` or ``V31WebhookRequestValidator`` - -.. code-block:: python - :emphasize-lines: 1,6 - - from openapi_core import V31RequestValidator + openapi.validate_request(webhook_request) - validate_request( - request, response, - spec=spec, - cls=V31RequestValidator, - ) +Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations/index`). -You can also explicitly import ``V3RequestValidator`` which is a shortcut to the latest OpenAPI v3 version. +You can also define your own request validator (See :doc:`customizations/request_validator_cls`). Response validation ------------------- @@ -66,9 +48,9 @@ Use ``validate_response`` function to validate response data against a given spe from openapi_core import validate_response # raises error if response is invalid - validate_response(request, response, spec=spec) + openapi.validate_response(request, response) -Response object should implement OpenAPI Response protocol (See :doc:`integrations`). +Response object should implement OpenAPI Response protocol (See :doc:`integrations/index`). .. note:: @@ -79,22 +61,6 @@ Use the same function to validate response data from webhook request against a g .. code-block:: python # raises error if request is invalid - validate_response(webhook_request, response, spec=spec) - -In order to explicitly validate a: - -* OpenAPI 3.0 spec, import ``V30ResponseValidator`` -* OpenAPI 3.1 spec, import ``V31ResponseValidator`` or ``V31WebhookResponseValidator`` - -.. code-block:: python - :emphasize-lines: 1,6 - - from openapi_core import V31ResponseValidator - - validate_response( - request, response, - spec=spec, - cls=V31ResponseValidator, - ) + openapi.validate_response(webhook_request, response) -You can also explicitly import ``V3ResponseValidator`` which is a shortcut to the latest OpenAPI v3 version. +You can also define your own response validator (See :doc:`customizations/response_validator_cls`). diff --git a/index.rst b/index.rst new file mode 100644 index 00000000..366a735e --- /dev/null +++ b/index.rst @@ -0,0 +1,20 @@ +.. openapi-core documentation master file, created by + sphinx-quickstart on Thu Nov 23 10:05:33 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to openapi-core's documentation! +======================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search`