@@ -543,6 +543,44 @@ def test_duplicate_properties(self, model_property_factory, string_property_fact
543543
544544 assert result .optional_props == [prop ], "There should only be one copy of duplicate properties"
545545
546+ def test_allof_required_override (self , model_property_factory , string_property_factory , config ):
547+ """Test that required field can be overridden in allOf schemas"""
548+ # Simulates:
549+ # FooBase:
550+ # type: object
551+ # properties:
552+ # bar: {type: string}
553+ # baz: {type: string}
554+ # FooCreate:
555+ # allOf:
556+ # - $ref: '#/components/schemas/FooBase'
557+ # - type: object
558+ # required: [bar]
559+ bar_prop = string_property_factory (name = "bar" , required = False )
560+ baz_prop = string_property_factory (name = "baz" , required = False )
561+
562+ data = oai .Schema .model_construct (
563+ allOf = [
564+ oai .Reference .model_construct (ref = "#/FooBase" ),
565+ oai .Schema .model_construct (type = "object" , required = ["bar" ]),
566+ ]
567+ )
568+ schemas = Schemas (
569+ classes_by_reference = {
570+ "/FooBase" : model_property_factory (
571+ required_properties = [], optional_properties = [bar_prop , baz_prop ]
572+ ),
573+ }
574+ )
575+
576+ result = _process_properties (data = data , schemas = schemas , class_name = "FooCreate" , config = config , roots = {"root" })
577+
578+ # bar should now be required, baz should remain optional
579+ assert len (result .required_props ) == 1
580+ assert result .required_props [0 ].name == "bar"
581+ assert len (result .optional_props ) == 1
582+ assert result .optional_props [0 ].name == "baz"
583+
546584 @pytest .mark .parametrize ("first_required" , [True , False ])
547585 @pytest .mark .parametrize ("second_required" , [True , False ])
548586 def test_mixed_requirements (
0 commit comments