File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,9 @@ Simple usage
8181 ...
8282 ValidationError: Additional properties are not allowed (' city' was unexpected)
8383
84+ Format check
85+ ************
86+
8487You can also check format for primitive types
8588
8689.. code-block :: python
@@ -93,6 +96,60 @@ You can also check format for primitive types
9396 ...
9497 ValidationError: ' -12' is not a ' date'
9598
99+ References
100+ **********
101+
102+ You can resolve JOSN references by passing custon reference resolver
103+
104+ .. code-block :: python
105+
106+ from jsonschema.validators import RefResolver
107+
108+ # A schema with reference
109+ schema = {
110+ " type" : " object" ,
111+ " required" : [
112+ " name"
113+ ],
114+ " properties" : {
115+ " name" : {
116+ " $ref" : " #/components/schemas/Name"
117+ },
118+ " age" : {
119+ " $ref" : " #/components/schemas/Age"
120+ },
121+ " birth-date" : {
122+ " $ref" : " #/components/schemas/BirthDate"
123+ }
124+ },
125+ " additionalProperties" : False ,
126+ }
127+ # Referenced schemas
128+ schemas = {
129+ " components" : {
130+ " schemas" : {
131+ " Name" : {
132+ " type" : " string"
133+ },
134+ " Age" : {
135+ " type" : " integer" ,
136+ " format" : " int32" ,
137+ " minimum" : 0 ,
138+ " nullable" : True ,
139+ },
140+ " BirthDate" : {
141+ " type" : " string" ,
142+ " format" : " date" ,
143+ }
144+ },
145+ },
146+ }
147+
148+ ref_resolver = RefResolver.from_schema(schemas)
149+
150+ validate({" name" : " John" , " age" : 23 }, schema, resolver = ref_resolver)
151+
152+ For more information about reference resolver see `Resolving JSON References <https://python-jsonschema.readthedocs.io/en/stable/references/ >`__
96153
97154Related projects
98155################
You can’t perform that action at this time.
0 commit comments