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.
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.
Thank you
No problem
FYI, there is still a codecov report that is still running...
There was a problem hiding this comment.
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
Hi
This PR adds a new custom BeforeValidator annotation based phone number type instead of the concrete type that exists:
PhoneNumberValidatorThis provides be an option for more composable phone number types, e.g: