diff --git a/connexion/validators/form_data.py b/connexion/validators/form_data.py index 6e7360d60..459ac7def 100644 --- a/connexion/validators/form_data.py +++ b/connexion/validators/form_data.py @@ -1,7 +1,7 @@ import logging import typing as t -from jsonschema import ValidationError, draft4_format_checker +from jsonschema import Draft4Validator, ValidationError from starlette.datastructures import Headers, UploadFile from starlette.formparsers import FormParser, MultiPartParser from starlette.types import Scope @@ -39,7 +39,7 @@ def __init__( @property def _validator(self): return Draft4RequestValidator( - self._schema, format_checker=draft4_format_checker + self._schema, format_checker=Draft4Validator.FORMAT_CHECKER ) @property diff --git a/connexion/validators/json.py b/connexion/validators/json.py index acfd96525..ff17b8f1d 100644 --- a/connexion/validators/json.py +++ b/connexion/validators/json.py @@ -3,7 +3,7 @@ import typing as t import jsonschema -from jsonschema import Draft4Validator, ValidationError, draft4_format_checker +from jsonschema import Draft4Validator, ValidationError from starlette.types import Scope from connexion.exceptions import BadRequestProblem, NonConformingResponseBody @@ -44,7 +44,7 @@ def __init__( @property def _validator(self): return Draft4RequestValidator( - self._schema, format_checker=draft4_format_checker + self._schema, format_checker=Draft4Validator.FORMAT_CHECKER ) async def _parse( @@ -86,7 +86,9 @@ class DefaultsJSONRequestBodyValidator(JSONRequestBodyValidator): @property def _validator(self): validator_cls = self.extend_with_set_default(Draft4RequestValidator) - return validator_cls(self._schema, format_checker=draft4_format_checker) + return validator_cls( + self._schema, format_checker=Draft4Validator.FORMAT_CHECKER + ) # via https://python-jsonschema.readthedocs.io/ @staticmethod @@ -111,7 +113,7 @@ class JSONResponseBodyValidator(AbstractResponseBodyValidator): @property def validator(self) -> Draft4Validator: return Draft4ResponseValidator( - self._schema, format_checker=draft4_format_checker + self._schema, format_checker=Draft4Validator.FORMAT_CHECKER ) def _parse(self, stream: t.Generator[bytes, None, None]) -> t.Any: diff --git a/docs/validation.rst b/docs/validation.rst index 096d42ccb..0e9da7fa3 100644 --- a/docs/validation.rst +++ b/docs/validation.rst @@ -325,18 +325,18 @@ Custom type formats ------------------- It is possible to define custom type formats for validation without adding a custom validator, by -leveraging the ``jsonschema.draft4_format_checker.checks`` decorator. +leveraging the ``jsonschema.Draft4Validator.FORMAT_CHECKER.checks`` decorator. We can for instance create a custom `money` format. .. code-block:: python import re - from jsonschema import draft4_format_checker + from jsonschema import Draft4Validator MONEY_RE = re.compile('^\$\s*\d+(\.\d\d)?') - @draft4_format_checker.checks('money') + @Draft4Validator.FORMAT_CHECKER.checks('money') def is_money(val): if not isinstance(val, str): return True