@@ -18,16 +18,14 @@ def _composition_example(composition="oneOf"):
18
18
19
19
20
20
@pytest .mark .parametrize (
21
- "composition, value" ,
22
- [("oneOf" , 10 ), ("allOf" , 15 ), ("anyOf" , 9 )]
21
+ "composition, value" , [("oneOf" , 10 ), ("allOf" , 15 ), ("anyOf" , 9 )]
23
22
)
24
23
def test_composition (asserter , composition , value ):
25
24
asserter (_composition_example (composition ), value , value )
26
25
27
26
28
27
@pytest .mark .parametrize (
29
- "composition, value" ,
30
- [("oneOf" , 2 ), ("anyOf" , 2 ), ("allOf" , 3 )]
28
+ "composition, value" , [("oneOf" , 2 ), ("anyOf" , 2 ), ("allOf" , 3 )]
31
29
)
32
30
def test_ref_is_expanded_on_composition_error (composition , value ):
33
31
with pytest .raises (JsonSchemaValueException ) as exc :
@@ -47,8 +45,7 @@ def test_ref_is_expanded_on_composition_error(composition, value):
47
45
48
46
49
47
@pytest .mark .parametrize (
50
- "composition, value" ,
51
- [("oneOf" , 2 ), ("anyOf" , 2 ), ("allOf" , 3 )]
48
+ "composition, value" , [("oneOf" , 2 ), ("anyOf" , 2 ), ("allOf" , 3 )]
52
49
)
53
50
def test_ref_is_expanded_with_resolver (composition , value ):
54
51
repo = {
@@ -76,3 +73,42 @@ def test_ref_is_expanded_with_resolver(composition, value):
76
73
assert composition == "allOf"
77
74
assert "$ref" not in exc .value .definition
78
75
assert exc .value .definition ["type" ] == "number"
76
+
77
+
78
+ def test_ref_in_conditional ():
79
+ repo = {
80
+ "sch://USA" : {"properties" : {"country" : {"const" : "United States of America" }}},
81
+ "sch://USA-post-code" : {
82
+ "properties" : {"postal_code" : {"pattern" : "[0-9]{5}(-[0-9]{4})?" }}
83
+ },
84
+ "sch://general-post-code" : {
85
+ "properties" : {
86
+ "postal_code" : {"pattern" : "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" }
87
+ }
88
+ },
89
+ }
90
+ schema = {
91
+ "type" : "object" ,
92
+ "properties" : {
93
+ "street_address" : {"type" : "string" },
94
+ "country" : {
95
+ "default" : "United States of America" ,
96
+ "enum" : ["United States of America" , "Canada" ],
97
+ },
98
+ },
99
+ "if" : {"allOf" : [{"$ref" : "sch://USA" }]},
100
+ "then" : {"oneOf" : [{"$ref" : "sch://USA-post-code" }]},
101
+ "else" : {"anyOf" : [{"$ref" : "sch://general-post-code" }]},
102
+ }
103
+ invalid = {
104
+ "street_address" : "1600 Pennsylvania Avenue NW" ,
105
+ "country" : "United States of America" ,
106
+ "postal_code" : "BS12 3FG" ,
107
+ }
108
+
109
+ with pytest .raises (JsonSchemaValueException ) as exc :
110
+ fastjsonschema .validate (schema , invalid , handlers = {"sch" : repo .__getitem__ })
111
+
112
+ assert exc .value .definition ["oneOf" ] == [
113
+ {"properties" : {"postal_code" : {"pattern" : "[0-9]{5}(-[0-9]{4})?" }}}
114
+ ]
0 commit comments