3636 numberWithStringValue: {"type": "number", "default": "5.5"}
3737 stringWithNumberValue: {"type": "string", "default": 6}
3838 stringConst: {"type": "string", "const": "always", "default": "always"}
39+ unionWithValidDefaultForType1:
40+ anyOf: [{"type": "boolean"}, {"type": "integer"}]
41+ default: true
42+ unionWithValidDefaultForType2:
43+ anyOf: [{"type": "boolean"}, {"type": "integer"}]
44+ default: 3
3945""" )
4046@with_generated_code_imports (".models.MyModel" )
4147class TestSimpleDefaults :
@@ -62,6 +68,8 @@ def test_defaults_in_initializer(self, MyModel):
6268 number_with_string_value = 5.5 ,
6369 string_with_number_value = "6" ,
6470 string_const = "always" ,
71+ union_with_valid_default_for_type_1 = True ,
72+ union_with_valid_default_for_type_2 = 3 ,
6573 )
6674
6775
@@ -131,6 +139,20 @@ def warnings(self):
131139 WithBadEnum:
132140 properties:
133141 badEnum: {"type": "string", "enum": ["a", "b"], "default": "x"}
142+ UnionWithNoValidDefault:
143+ properties:
144+ badBoolOrInt:
145+ anyOf:
146+ - type: boolean
147+ - type: integer
148+ default: "xxx"
149+
150+ PropWithNoDefault:
151+ type: boolean
152+ PropWithOverriddenDefault:
153+ allOf:
154+ - $ref: "#/components/schemas/PropWithNoDefault"
155+ - default: "not a valid boolean"
134156"""
135157 )
136158 # Note, the null/None type, and binary strings (files), are not covered here due to a known bug:
@@ -151,6 +173,7 @@ def warnings(self):
151173 ("WithBadUuidAsString" , "Invalid UUID value" ),
152174 ("WithBadUuidAsOther" , "Invalid UUID value" ),
153175 ("WithBadEnum" , "Value x is not valid for enum" ),
176+ ("UnionWithNoValidDefault" , "Invalid int value" ),
154177 ]
155178 )
156179 def test_bad_default_warning (self , model_name , message , warnings ):
0 commit comments