@@ -43,7 +43,7 @@ Simple usage
4343
4444.. code-block :: python
4545
46- from openapi_schema_validator import OAS30Validator, oas30_format_checker
46+ from openapi_schema_validator import validate
4747
4848 # A sample schema
4949 schema = {
@@ -61,20 +61,37 @@ Simple usage
6161 " minimum" : 0 ,
6262 " nullable" : True ,
6363 },
64+ " birth-date" : {
65+ " type" : " string" ,
66+ " format" : " date" ,
67+ }
6468 },
6569 " additionalProperties" : False ,
6670 }
6771
68- validator = OAS30Validator(schema)
6972 # If no exception is raised by validate(), the instance is valid.
70- validator. validate({" name" : " John" , " age" : 23 })
73+ validate({" name" : " John" , " age" : 23 }, schema )
7174
72- validator. validate({" name" : " John" , " city" : " London" })
75+ validate({" name" : " John" , " city" : " London" }, schema )
7376
7477 Traceback (most recent call last):
7578 ...
7679 ValidationError: Additional properties are not allowed (' city' was unexpected)
7780
81+
82+ You can also check format for primitive types
83+
84+ .. code- block:: python
85+
86+ from openapi_schema_validator import oas30_format_checker
87+
88+ validate({" name" : " John" , " birth-date" : " -12" }, schema, format_checker = oas30_format_checker)
89+
90+ Traceback (most recent call last):
91+ ...
92+ ValidationError: ' -12' is not a ' date'
93+
94+
7895Related projects
7996# ###############
8097* `openapi- core < https:// github.com/ p1c2u/ openapi- core> ` __
0 commit comments