From a150c949151c5b5e8a2e5c67f1d3d2da0d3bca35 Mon Sep 17 00:00:00 2001 From: Renja Date: Sat, 29 Jul 2023 12:28:45 +0200 Subject: [PATCH] Changed doc indentation from 3 to 4 --- README.rst | 42 +++--- docs/contributing.rst | 12 +- docs/customizations.rst | 40 ++--- docs/extensions.rst | 16 +- docs/index.rst | 54 +++---- docs/integrations.rst | 192 ++++++++++++------------ docs/security.rst | 12 +- docs/unmarshalling.rst | 62 ++++---- docs/validation.rst | 36 ++--- openapi_core/contrib/django/requests.py | 6 +- 10 files changed, 236 insertions(+), 236 deletions(-) diff --git a/README.rst b/README.rst index ef76a99e..50c60b50 100644 --- a/README.rst +++ b/README.rst @@ -45,13 +45,13 @@ Recommended way (via pip): .. code-block:: console - pip install openapi-core + pip install openapi-core Alternatively you can download the code and install from the repository: .. code-block:: console - pip install -e git+https://github.com/python-openapi/openapi-core.git#egg=openapi_core + pip install -e git+https://github.com/python-openapi/openapi-core.git#egg=openapi_core First steps @@ -61,32 +61,32 @@ Firstly create your specification object. .. code-block:: python - from openapi_core import Spec + from openapi_core import Spec - spec = Spec.from_file_path('openapi.json') + spec = Spec.from_file_path('openapi.json') Now you can use it to validate and unmarshal against requests and/or responses. .. code-block:: python - from openapi_core import unmarshal_request + from openapi_core import unmarshal_request - # raises error if request is invalid - result = unmarshal_request(request, spec=spec) + # raises error if request is invalid + result = unmarshal_request(request, spec=spec) Retrieve validated and unmarshalled request data .. code-block:: python - # get parameters - path_params = result.parameters.path - query_params = result.parameters.query - cookies_params = result.parameters.cookies - headers_params = result.parameters.headers - # get body - body = result.body - # get security data - security = result.security + # get parameters + path_params = result.parameters.path + query_params = result.parameters.query + cookies_params = result.parameters.cookies + headers_params = result.parameters.headers + # get body + body = result.body + # get security data + security = result.security Request object should implement OpenAPI Request protocol. Check `Integrations `__ to find officially supported implementations. @@ -98,15 +98,15 @@ If you just want to validate your request/response data without unmarshalling, r Related projects ################ * `openapi-spec-validator `__ - Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification. + Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification. * `openapi-schema-validator `__ - Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1. + Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1. * `bottle-openapi-3 `__ - OpenAPI 3.0 Support for the Bottle Web Framework + OpenAPI 3.0 Support for the Bottle Web Framework * `pyramid_openapi3 `__ - Pyramid addon for OpenAPI3 validation of requests and responses. + Pyramid addon for OpenAPI3 validation of requests and responses. * `tornado-openapi3 `__ - Tornado OpenAPI 3 request and response validation library. + Tornado OpenAPI 3 request and response validation library. License diff --git a/docs/contributing.rst b/docs/contributing.rst index 058818d8..938bd688 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -33,7 +33,7 @@ Install `Poetry `__ by following the `official instal .. code-block:: console - poetry config virtualenvs.in-project true + poetry config virtualenvs.in-project true Setup ^^^^^ @@ -42,13 +42,13 @@ To create a development environment and install the runtime and development depe .. code-block:: console - poetry install + poetry install Then enter the virtual environment created by Poetry: .. code-block:: console - poetry shell + poetry shell Static checks ^^^^^^^^^^^^^ @@ -59,18 +59,18 @@ To turn on pre-commit checks for commit operations in git, enter: .. code-block:: console - pre-commit install + pre-commit install To run all checks on your staged files, enter: .. code-block:: console - pre-commit run + pre-commit run To run all checks on all files, enter: .. code-block:: console - pre-commit run --all-files + pre-commit run --all-files Pre-commit check results are also attached to your PR through integration with Github Action. diff --git a/docs/customizations.rst b/docs/customizations.rst index f215895b..679dedcd 100644 --- a/docs/customizations.rst +++ b/docs/customizations.rst @@ -11,12 +11,12 @@ If you know you have a valid specification already, disabling the validator can .. code-block:: python :emphasize-lines: 5 - from openapi_core import Spec + from openapi_core import Spec - spec = Spec.from_dict( + spec = Spec.from_dict( spec_dict, validator=None, - ) + ) Media type deserializers ------------------------ @@ -28,20 +28,20 @@ You can also define your own ones. Pass custom defined media type deserializers .. code-block:: python :emphasize-lines: 13 - def protobuf_deserializer(message): + def protobuf_deserializer(message): feature = route_guide_pb2.Feature() feature.ParseFromString(message) return feature - extra_media_type_deserializers = { + extra_media_type_deserializers = { 'application/protobuf': protobuf_deserializer, - } + } - result = unmarshal_response( + result = unmarshal_response( request, response, spec=spec, extra_media_type_deserializers=extra_media_type_deserializers, - ) + ) Format validators ----------------- @@ -55,20 +55,20 @@ Here's how you could add support for a ``usdate`` format that handles dates of t .. code-block:: python :emphasize-lines: 13 - import re + import re - def validate_usdate(value): + def validate_usdate(value): return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value)) - extra_format_validators = { + extra_format_validators = { 'usdate': validate_usdate, - } + } - validate_response( + validate_response( request, response, spec=spec, extra_format_validators=extra_format_validators, - ) + ) Format unmarshallers -------------------- @@ -82,17 +82,17 @@ Here's an example with the ``usdate`` format that converts a value to date objec .. code-block:: python :emphasize-lines: 13 - from datetime import datetime + from datetime import datetime - def unmarshal_usdate(value): + def unmarshal_usdate(value): return datetime.strptime(value, "%m/%d/%y").date - extra_format_unmarshallers = { + extra_format_unmarshallers = { 'usdate': unmarshal_usdate, - } + } - result = unmarshal_response( + result = unmarshal_response( request, response, spec=spec, extra_format_unmarshallers=extra_format_unmarshallers, - ) + ) diff --git a/docs/extensions.rst b/docs/extensions.rst index 7673fdff..eaa3bf85 100644 --- a/docs/extensions.rst +++ b/docs/extensions.rst @@ -9,8 +9,8 @@ By default, objects are unmarshalled to dictionaries. You can use dynamically cr .. code-block:: yaml :emphasize-lines: 5 - ... - components: + ... + components: schemas: Coordinates: x-model: Coordinates @@ -35,8 +35,8 @@ You can use your own dataclasses, pydantic models or models generated by third p .. code-block:: yaml :emphasize-lines: 5 - ... - components: + ... + components: schemas: Coordinates: x-model-path: foo.bar.Coordinates @@ -52,11 +52,11 @@ You can use your own dataclasses, pydantic models or models generated by third p .. code-block:: python - # foo/bar.py - from dataclasses import dataclass + # foo/bar.py + from dataclasses import dataclass - @dataclass - class Coordinates: + @dataclass + class Coordinates: lat: float lon: float diff --git a/docs/index.rst b/docs/index.rst index 18c0c3cc..587156a1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,16 +2,16 @@ openapi-core ============ .. toctree:: - :hidden: - :maxdepth: 2 + :hidden: + :maxdepth: 2 - unmarshalling - validation - integrations - customizations - security - extensions - contributing + unmarshalling + validation + integrations + customizations + security + extensions + contributing Openapi-core is a Python library that adds client-side and server-side support for the `OpenAPI v3.0 `__ @@ -30,13 +30,13 @@ Installation .. md-tab-set:: - .. md-tab-item:: Pip + PyPI (recommented) + .. md-tab-item:: Pip + PyPI (recommented) .. code-block:: console pip install openapi-core - .. md-tab-item:: Pip + the source + .. md-tab-item:: Pip + the source .. code-block:: console @@ -49,32 +49,32 @@ Firstly create your specification object. .. code-block:: python - from openapi_core import Spec + from openapi_core import Spec - spec = Spec.from_file_path('openapi.json') + spec = Spec.from_file_path('openapi.json') Now you can use it to validate and unmarshal your requests and/or responses. .. code-block:: python - from openapi_core import unmarshal_request + from openapi_core import unmarshal_request - # raises error if request is invalid - result = unmarshal_request(request, spec=spec) + # raises error if request is invalid + result = unmarshal_request(request, spec=spec) Retrieve validated and unmarshalled request data .. code-block:: python - # get parameters - path_params = result.parameters.path - query_params = result.parameters.query - cookies_params = result.parameters.cookies - headers_params = result.parameters.headers - # get body - body = result.body - # get security data - security = result.security + # get parameters + path_params = result.parameters.path + query_params = result.parameters.query + cookies_params = result.parameters.cookies + headers_params = result.parameters.headers + # get body + body = result.body + # get security data + security = result.security Request object should implement OpenAPI Request protocol. Check :doc:`integrations` to find oficially supported implementations. @@ -86,9 +86,9 @@ Related projects ---------------- * `openapi-spec-validator `__ - Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification. + Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification. * `openapi-schema-validator `__ - Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1. + Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1. License ------- diff --git a/docs/integrations.rst b/docs/integrations.rst index 4a5fbd26..96229b91 100644 --- a/docs/integrations.rst +++ b/docs/integrations.rst @@ -15,22 +15,22 @@ 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 + 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) + 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 + 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) + openapi_response = StarletteOpenAPIResponse(aiohttp_response) + result = unmarshal_response(openapi_request, openapi_response, spec=spec) Bottle @@ -53,23 +53,23 @@ Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your .. code-block:: python :emphasize-lines: 6,9 - # settings.py - from openapi_core import Spec + # settings.py + from openapi_core import Spec - MIDDLEWARE = [ + MIDDLEWARE = [ # ... 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', - ] + ] - OPENAPI_SPEC = Spec.from_dict(spec_dict) + OPENAPI_SPEC = Spec.from_dict(spec_dict) 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 + from django.views import View - class MyView(View): + class MyView(View): def get(self, req): # get parameters object with path, query, cookies and headers parameters validated_params = req.openapi.parameters @@ -89,21 +89,21 @@ 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 + 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) + 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 + 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) + openapi_response = DjangoOpenAPIResponse(django_response) + result = unmarshal_response(openapi_request, openapi_response, spec=spec) Falcon @@ -120,37 +120,37 @@ 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 + from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware - openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec) + openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec) - app = falcon.App( + 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 + from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware - openapi_middleware = FalconOpenAPIMiddleware.from_spec( + openapi_middleware = FalconOpenAPIMiddleware.from_spec( spec, extra_format_validators=extra_format_validators, - ) + ) - app = falcon.App( + 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: + class ThingsResource: def on_get(self, req, resp): # get parameters object with path, query, cookies and headers parameters validated_params = req.context.openapi.parameters @@ -170,21 +170,21 @@ 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 + 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) + 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 + 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) + openapi_response = FalconOpenAPIResponse(falcon_response) + result = unmarshal_response(openapi_request, openapi_response, spec=spec) Flask @@ -200,13 +200,13 @@ Flask views can be integrated by ``FlaskOpenAPIViewDecorator`` decorator. .. code-block:: python :emphasize-lines: 1,3,6 - from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator + from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator - openapi = FlaskOpenAPIViewDecorator.from_spec(spec) + openapi = FlaskOpenAPIViewDecorator.from_spec(spec) - @app.route('/home') - @openapi - def home(): + @app.route('/home') + @openapi + def home(): return "Welcome home" Additional customization parameters can be passed to the decorator. @@ -214,25 +214,25 @@ Additional customization parameters can be passed to the decorator. .. code-block:: python :emphasize-lines: 5 - from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator + from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator - openapi = FlaskOpenAPIViewDecorator.from_spec( + openapi = FlaskOpenAPIViewDecorator.from_spec( spec, extra_format_validators=extra_format_validators, - ) + ) If you want to decorate class based view you can use the decorators attribute: .. code-block:: python :emphasize-lines: 2 - class MyView(View): + class MyView(View): decorators = [openapi] def dispatch_request(self): return "Welcome home" - app.add_url_rule('/home', view_func=MyView.as_view('home')) + app.add_url_rule('/home', view_func=MyView.as_view('home')) View ~~~~ @@ -242,35 +242,35 @@ As an alternative to the decorator-based integration, a Flask method based views .. code-block:: python :emphasize-lines: 1,3,8 - from openapi_core.contrib.flask.views import FlaskOpenAPIView + from openapi_core.contrib.flask.views import FlaskOpenAPIView - class MyView(FlaskOpenAPIView): + class MyView(FlaskOpenAPIView): def get(self): return "Welcome home" - app.add_url_rule( + 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 + from openapi_core.contrib.flask.views import FlaskOpenAPIView - class MyView(FlaskOpenAPIView): + class MyView(FlaskOpenAPIView): def get(self): return "Welcome home" - app.add_url_rule( + app.add_url_rule( '/home', view_func=MyView.as_view( 'home', spec, extra_format_validators=extra_format_validators, ), - ) + ) Request parameters ~~~~~~~~~~~~~~~~~~ @@ -280,11 +280,11 @@ In Flask, all unmarshalled request data are provided as Flask request object's ` .. code-block:: python :emphasize-lines: 6,7 - from flask.globals import request + from flask.globals import request - @app.route('/browse//') - @openapi - def browse(id): + @app.route('/browse//') + @openapi + def browse(id): browse_id = request.openapi.parameters.path['id'] page = request.openapi.parameters.query.get('page', 1) @@ -297,11 +297,11 @@ 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 + 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) + openapi_request = FlaskOpenAPIRequest(flask_request) + result = unmarshal_request(openapi_request, spec=spec) For response factory see `Werkzeug`_ integration. @@ -324,32 +324,32 @@ 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 + 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) + 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 + 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) + 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 + 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) + openapi_webhook_request = RequestsOpenAPIWebhookRequest(requests_request, "my_webhook") + result = unmarshal_request(openapi_webhook_request, spec=spec) Starlette @@ -364,21 +364,21 @@ 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 + 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) + 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 + 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) + openapi_response = StarletteOpenAPIResponse(starlette_response) + result = unmarshal_response(openapi_request, openapi_response, spec=spec) Tornado @@ -399,18 +399,18 @@ 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 + 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) + 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 + 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) + openapi_response = WerkzeugOpenAPIResponse(werkzeug_response) + result = unmarshal_response(openapi_request, openapi_response, spec=spec) diff --git a/docs/security.rst b/docs/security.rst index 596201a0..fc0e9a90 100644 --- a/docs/security.rst +++ b/docs/security.rst @@ -12,10 +12,10 @@ Here's an example with scheme ``BasicAuth`` and ``ApiKeyAuth`` security schemes: .. code-block:: yaml - security: + security: - BasicAuth: [] - ApiKeyAuth: [] - components: + components: securitySchemes: BasicAuth: type: http @@ -29,8 +29,8 @@ Security schemes data are accessible from `security` attribute of `RequestUnmars .. code-block:: python - # get basic auth decoded credentials - result.security['BasicAuth'] + # get basic auth decoded credentials + result.security['BasicAuth'] - # get api key - result.security['ApiKeyAuth'] + # get api key + result.security['ApiKeyAuth'] diff --git a/docs/unmarshalling.rst b/docs/unmarshalling.rst index 66119137..5a7eb17b 100644 --- a/docs/unmarshalling.rst +++ b/docs/unmarshalling.rst @@ -22,23 +22,23 @@ Use ``unmarshal_request`` function to validate and unmarshal request data agains .. code-block:: python - from openapi_core import unmarshal_request + from openapi_core import unmarshal_request - # raises error if request is invalid - result = unmarshal_request(request, spec=spec) + # raises error if request is invalid + result = unmarshal_request(request, spec=spec) Request object should implement OpenAPI Request protocol (See :doc:`integrations`). .. note:: - Webhooks feature is part of OpenAPI v3.1 only + Webhooks feature is part of OpenAPI v3.1 only Use the same function 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) + # raises error if request is invalid + result = unmarshal_request(webhook_request, spec=spec) Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations`). @@ -46,15 +46,15 @@ Retrieve validated and unmarshalled request data .. code-block:: python - # get parameters - path_params = result.parameters.path - query_params = result.parameters.query - cookies_params = result.parameters.cookies - headers_params = result.parameters.headers - # get body - body = result.body - # get security data - security = result.security + # get parameters + path_params = result.parameters.path + query_params = result.parameters.query + cookies_params = result.parameters.cookies + headers_params = result.parameters.headers + # get body + body = result.body + # get security data + security = result.security In order to explicitly validate and unmarshal a: @@ -64,13 +64,13 @@ In order to explicitly validate and unmarshal a: .. code-block:: python :emphasize-lines: 1,6 - from openapi_core import V31RequestUnmarshaller + from openapi_core import V31RequestUnmarshaller - result = unmarshal_request( + 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. @@ -81,32 +81,32 @@ Use ``unmarshal_response`` function to validate and unmarshal response data agai .. code-block:: python - from openapi_core import unmarshal_response + from openapi_core import unmarshal_response - # raises error if response is invalid - result = unmarshal_response(request, response, spec=spec) + # raises error if response is invalid + result = unmarshal_response(request, response, spec=spec) Response object should implement OpenAPI Response protocol (See :doc:`integrations`). .. note:: - Webhooks feature is part of OpenAPI v3.1 only + 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. .. code-block:: python - # raises error if request is invalid - result = unmarshal_response(webhook_request, response, spec=spec) + # raises error if request is invalid + result = unmarshal_response(webhook_request, response, spec=spec) Retrieve validated and unmarshalled response data .. code-block:: python - # get headers - headers = result.headers - # get data - data = result.data + # get headers + headers = result.headers + # get data + data = result.data In order to explicitly validate and unmarshal a: @@ -116,12 +116,12 @@ In order to explicitly validate and unmarshal a: .. code-block:: python :emphasize-lines: 1,6 - from openapi_core import V31ResponseUnmarshaller + from openapi_core import V31ResponseUnmarshaller - result = unmarshal_response( + 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. diff --git a/docs/validation.rst b/docs/validation.rst index 8cf2c24c..829c28c2 100644 --- a/docs/validation.rst +++ b/docs/validation.rst @@ -18,23 +18,23 @@ Use ``validate_request`` function to validate request data against a given spec. .. code-block:: python - from openapi_core import validate_request + from openapi_core import validate_request - # raises error if request is invalid - validate_request(request, spec=spec) + # raises error if request is invalid + validate_request(request, spec=spec) Request object should implement OpenAPI Request protocol (See :doc:`integrations`). .. note:: - Webhooks feature is part of OpenAPI v3.1 only + Webhooks feature is part of OpenAPI v3.1 only Use the same function to validate webhook request data against a given spec. .. code-block:: python - # raises error if request is invalid - validate_request(webhook_request, spec=spec) + # raises error if request is invalid + validate_request(webhook_request, spec=spec) Webhook request object should implement OpenAPI WebhookRequest protocol (See :doc:`integrations`). @@ -46,13 +46,13 @@ In order to explicitly validate and unmarshal a: .. code-block:: python :emphasize-lines: 1,6 - from openapi_core import V31RequestValidator + from openapi_core import V31RequestValidator - validate_request( + validate_request( request, response, spec=spec, cls=V31RequestValidator, - ) + ) You can also explicitly import ``V3RequestValidator`` which is a shortcut to the latest OpenAPI v3 version. @@ -63,23 +63,23 @@ Use ``validate_response`` function to validate response data against a given spe .. code-block:: python - from openapi_core import validate_response + from openapi_core import validate_response - # raises error if response is invalid - validate_response(request, response, spec=spec) + # raises error if response is invalid + validate_response(request, response, spec=spec) Response object should implement OpenAPI Response protocol (See :doc:`integrations`). .. note:: - Webhooks feature is part of OpenAPI v3.1 only + Webhooks feature is part of OpenAPI v3.1 only Use the same function to validate response data from webhook request against a given spec. .. code-block:: python - # raises error if request is invalid - validate_response(webhook_request, response, spec=spec) + # raises error if request is invalid + validate_response(webhook_request, response, spec=spec) In order to explicitly validate a: @@ -89,12 +89,12 @@ In order to explicitly validate a: .. code-block:: python :emphasize-lines: 1,6 - from openapi_core import V31ResponseValidator + from openapi_core import V31ResponseValidator - validate_response( + validate_response( request, response, spec=spec, cls=V31ResponseValidator, - ) + ) You can also explicitly import ``V3ResponseValidator`` which is a shortcut to the latest OpenAPI v3 version. diff --git a/openapi_core/contrib/django/requests.py b/openapi_core/contrib/django/requests.py index dffe0387..2d017bcb 100644 --- a/openapi_core/contrib/django/requests.py +++ b/openapi_core/contrib/django/requests.py @@ -11,9 +11,9 @@ # https://docs.djangoproject.com/en/stable/topics/http/urls/ # # Currently unsupported are : -# - nested arguments, e.g.: ^comments/(?:page-(?P\d+)/)?$ -# - unnamed regex groups, e.g.: ^articles/([0-9]{4})/$ -# - multiple named parameters between a single pair of slashes +# - nested arguments, e.g.: ^comments/(?:page-(?P\d+)/)?$ +# - unnamed regex groups, e.g.: ^articles/([0-9]{4})/$ +# - multiple named parameters between a single pair of slashes # e.g.: -/edit/ # # The regex matches everything, except a "/" until "<". Then only the name