The documentation on how to how to implement custom type formats suggest doing something like this
import re
from jsonschema import draft4_format_checker
MONEY_RE = re.compile('^\$\s*\d+(\.\d\d)?')
@draft4_format_checker.checks('money')
def is_money(val):
if not isinstance(val, str):
return True
return MONEY_RE.match(val)
But doing that results in the following error
DeprecationWarning: Accessing jsonschema.draft4_format_checker is deprecated and will be removed in a future release. Instead, use the FORMAT_CHECKER attribute on the corresponding Validator.
I tried to solve it by doing like this instead
import re
from jsonschema import draft4_format_checker
MONEY_RE = re.compile('^\$\s*\d+(\.\d\d)?')
@Draft7Validator.FORMAT_CHECKER.checks('money')
def is_money(val):
if not isinstance(val, str):
return True
return MONEY_RE.match(val)
This seems to be the wrong way of doing it since the custom type is not being validated at all.
If I can get some assistance on how to solve this correctly I'd be happy to create a PR altering the documentation as needed.
The documentation on how to how to implement custom type formats suggest doing something like this
But doing that results in the following error
DeprecationWarning: Accessing jsonschema.draft4_format_checker is deprecated and will be removed in a future release. Instead, use the FORMAT_CHECKER attribute on the corresponding Validator.
I tried to solve it by doing like this instead
This seems to be the wrong way of doing it since the custom type is not being validated at all. If I can get some assistance on how to solve this correctly I'd be happy to create a PR altering the documentation as needed.