@@ -53,17 +53,11 @@ def test_one_of_validator():
5353
5454 dumped = validate_and_dump (schema )
5555
56- assert dumped ["definitions" ]["UserSchema" ]["properties" ]["sex" ]["enum" ] == [
57- "male" ,
58- "female" ,
59- "non_binary" ,
60- "other" ,
61- ]
62- assert dumped ["definitions" ]["UserSchema" ]["properties" ]["sex" ]["enumNames" ] == [
63- "Male" ,
64- "Female" ,
65- "Non-binary/fluid" ,
66- "Other" ,
56+ assert dumped ["definitions" ]["UserSchema" ]["properties" ]["sex" ]["oneOf" ] == [
57+ {"type" : "string" , "title" : "Male" , "const" : "male" },
58+ {"type" : "string" , "title" : "Female" , "const" : "female" },
59+ {"type" : "string" , "title" : "Non-binary/fluid" , "const" : "non_binary" },
60+ {"type" : "string" , "title" : "Other" , "const" : "other" },
6761 ]
6862
6963
@@ -76,8 +70,35 @@ class TestSchema(Schema):
7670 dumped = validate_and_dump (schema )
7771
7872 foo_property = dumped ["definitions" ]["TestSchema" ]["properties" ]["foo" ]
79- assert foo_property ["enum" ] == []
80- assert foo_property ["enumNames" ] == []
73+ assert "oneOf" not in foo_property
74+
75+
76+ def test_one_of_object ():
77+ class TestSchema (Schema ):
78+ foo = fields .Dict (validate = OneOf ([{"a" : 1 }]))
79+
80+ schema = TestSchema ()
81+
82+ dumped = validate_and_dump (schema )
83+
84+ foo_property = dumped ["definitions" ]["TestSchema" ]["properties" ]["foo" ]
85+ assert "oneOf" not in foo_property
86+
87+
88+ def test_one_of_custom_field ():
89+ class CustomField (fields .String ):
90+ def _jsonschema_type_mapping (self ):
91+ return {"type" : "string" , "oneOf" : [{"const" : "one" }, {"const" : "two" }]}
92+
93+ class TestSchema (Schema ):
94+ foo = CustomField (validate = OneOf (["one" , "two" ]))
95+
96+ schema = TestSchema ()
97+
98+ dumped = validate_and_dump (schema )
99+
100+ foo_property = dumped ["definitions" ]["TestSchema" ]["properties" ]["foo" ]
101+ assert foo_property ["oneOf" ] == [{"const" : "one" }, {"const" : "two" }]
81102
82103
83104def test_range ():
0 commit comments