Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following example in documentation gives DeprecationWarning #1914

Closed
johanfrykebrant opened this issue Apr 24, 2024 · 1 comment
Closed

Following example in documentation gives DeprecationWarning #1914

johanfrykebrant opened this issue Apr 24, 2024 · 1 comment

Comments

@johanfrykebrant
Copy link

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.

@rtb-zla-karma
Copy link

Related to #1786 .

virajkanwade added a commit to virajkanwade/connexion that referenced this issue Sep 10, 2024
RobbeSneyders added a commit that referenced this issue Oct 23, 2024
Fixes #1786  #1914 .



Changes proposed in this pull request:

 -
 -
 -

---------

Co-authored-by: Robbe Sneyders <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants