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
81
81
...
82
82
ValidationError: Additional properties are not allowed (' city' was unexpected)
83
83
84
+ Format check
85
+ ************
86
+
84
87
You can also check format for primitive types
85
88
86
89
.. code-block :: python
@@ -93,6 +96,60 @@ You can also check format for primitive types
93
96
...
94
97
ValidationError: ' -12' is not a ' date'
95
98
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/ >`__
96
153
97
154
Related projects
98
155
################
You can’t perform that action at this time.
0 commit comments