@@ -201,6 +201,54 @@ def test_string_uuid(self, value):
201
201
202
202
assert result is None
203
203
204
+ def test_ref (self ):
205
+ schema = {
206
+ "$ref" : "#/$defs/Pet" ,
207
+ "$defs" : {
208
+ "Pet" : {
209
+ "required" : ["id" , "name" ],
210
+ "properties" : {
211
+ "id" : {"type" : "integer" , "format" : "int64" },
212
+ "name" : {"type" : "string" },
213
+ "tag" : {"type" : "string" },
214
+ },
215
+ }
216
+ },
217
+ }
218
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
219
+
220
+ result = validator .validate ({"id" : 1 , "name" : "John" })
221
+ assert result is None
222
+
223
+ with pytest .raises (ValidationError ) as excinfo :
224
+ validator .validate ({"name" : "John" })
225
+
226
+ error = "'id' is a required property"
227
+ assert error in str (excinfo .value )
228
+
229
+ @pytest .mark .xfail (reason = "Issue #20" )
230
+ def test_ref_nullable (self ):
231
+ schema = {
232
+ "nullable" : True ,
233
+ "allOf" : [
234
+ {
235
+ "$ref" : "#/$defs/Pet" ,
236
+ },
237
+ ],
238
+ "$defs" : {
239
+ "Pet" : {
240
+ "required" : ["id" , "name" ],
241
+ "properties" : {
242
+ "id" : {"type" : "integer" , "format" : "int64" },
243
+ "name" : {"type" : "string" },
244
+ "tag" : {"type" : "string" },
245
+ },
246
+ }
247
+ },
248
+ }
249
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
250
+ validator .validate (None )
251
+
204
252
def test_allof_required (self ):
205
253
schema = {
206
254
"allOf" : [
@@ -217,6 +265,20 @@ def test_allof_required(self):
217
265
):
218
266
validator .validate ({"another_prop" : "bla" })
219
267
268
+ @pytest .mark .xfail (reason = "Issue #20" )
269
+ def test_allof_nullable (self ):
270
+ schema = {
271
+ "allOf" : [
272
+ {
273
+ "type" : "object" ,
274
+ "properties" : {"some_prop" : {"type" : "string" }},
275
+ },
276
+ {"type" : "object" , "nullable" : True },
277
+ ]
278
+ }
279
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
280
+ validator .validate (None )
281
+
220
282
def test_required (self ):
221
283
schema = {
222
284
"type" : "object" ,
@@ -665,7 +727,7 @@ def test_schema_validation(self):
665
727
error = "'-12' is not a 'date'"
666
728
assert error in str (excinfo .value )
667
729
668
- def test_schema_ref (self ):
730
+ def test_ref (self ):
669
731
schema = {
670
732
"$ref" : "#/$defs/Pet" ,
671
733
"$defs" : {
@@ -693,6 +755,28 @@ def test_schema_ref(self):
693
755
error = "'id' is a required property"
694
756
assert error in str (excinfo .value )
695
757
758
+ def test_ref_nullable (self ):
759
+ # specifying an array for type only works with primitive types
760
+ schema = {
761
+ "oneOf" : [
762
+ {"type" : "null" },
763
+ {"$ref" : "#/$defs/Pet" },
764
+ ],
765
+ "$defs" : {
766
+ "Pet" : {
767
+ "type" : "object" ,
768
+ "required" : ["id" , "name" ],
769
+ "properties" : {
770
+ "id" : {"type" : "integer" , "format" : "int64" },
771
+ "name" : {"type" : "string" },
772
+ "tag" : {"type" : "string" },
773
+ },
774
+ }
775
+ },
776
+ }
777
+ validator = OAS31Validator (schema , format_checker = oas30_format_checker )
778
+ validator .validate (None )
779
+
696
780
@pytest .mark .parametrize (
697
781
"value" ,
698
782
[
0 commit comments