-
Notifications
You must be signed in to change notification settings - Fork 55
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
Feature: Add phone number validator #203
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 11 17 +6
Lines 685 999 +314
Branches 169 244 +75
==========================================
+ Hits 685 999 +314 ☔ View full report in Codecov by Sentry. |
def test_json_schema() -> None: | ||
assert Numbers.model_json_schema() == { | ||
'title': 'Numbers', | ||
'type': 'object', | ||
'properties': { | ||
'phone_number': { | ||
'title': 'Phone Number', | ||
'anyOf': [ | ||
{'type': 'string', 'format': 'phone'}, | ||
{'type': 'null'}, | ||
], | ||
'default': None, | ||
}, | ||
'na_number': { | ||
'title': 'Na Number', | ||
'anyOf': [ | ||
{'type': 'string', 'format': 'phone'}, | ||
{'type': 'null'}, | ||
], | ||
'default': None, | ||
}, | ||
'uk_number': { | ||
'title': 'Uk Number', | ||
'anyOf': [ | ||
{'type': 'string', 'format': 'phone'}, | ||
{'type': 'null'}, | ||
], | ||
'default': None, | ||
}, | ||
}, | ||
} | ||
|
||
class SomethingElse(BaseModel): | ||
phone_number: Number | ||
|
||
assert SomethingElse.model_json_schema() == { | ||
'title': 'SomethingElse', | ||
'type': 'object', | ||
'properties': { | ||
'phone_number': { | ||
'title': 'Phone Number', | ||
'type': 'string', | ||
'format': 'phone', | ||
} | ||
}, | ||
'required': ['phone_number'], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @mZbZ but can you migrate this part of the tests to tests/test_json_schema.py
in the tests directory so we can keep the tree of tests follow a pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
No problem
FYI, there is still a codecov report that is still running...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
No problem
FYI, there is still a codecov report that is still running...
somethings its get bugged and stick like this you can try another change or an empty commit and its will be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Hi
This PR adds a new custom BeforeValidator annotation based phone number type instead of the concrete type that exists:
PhoneNumberValidator
This provides be an option for more composable phone number types, e.g: