File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -111,18 +111,21 @@ class SchemaValidator(object):
111111 def __init__ (self , dereferencer ):
112112 self .dereferencer = dereferencer
113113
114- def iter_errors (self , schema ):
114+ def iter_errors (self , schema , require_properties = True ):
115115 schema_deref = self .dereferencer .dereference (schema )
116116
117117 if 'allOf' in schema_deref :
118118 for inner_schema in schema_deref ['allOf' ]:
119- for err in self .iter_errors (inner_schema ):
119+ for err in self .iter_errors (
120+ inner_schema ,
121+ require_properties = False
122+ ):
120123 yield err
121124
122125 required = schema_deref .get ('required' , [])
123126 properties = schema_deref .get ('properties' , {}).keys ()
124127 extra_properties = list (set (required ) - set (properties ))
125- if extra_properties :
128+ if extra_properties and require_properties :
126129 yield ExtraParametersError (
127130 "Required list has not defined properties: {0}" .format (
128131 extra_properties
Original file line number Diff line number Diff line change @@ -82,6 +82,40 @@ def test_same_parameters_names(self, validator):
8282 errors_list = list (errors )
8383 assert errors_list == []
8484
85+ def test_allow_allof_required_no_properties (self , validator ):
86+ spec = {
87+ 'openapi' : '3.0.0' ,
88+ 'info' : {
89+ 'title' : 'Test Api' ,
90+ 'version' : '0.0.1' ,
91+ },
92+ 'paths' : {},
93+ 'components' : {
94+ 'schemas' : {
95+ 'Credit' : {
96+ 'type' : 'object' ,
97+ 'properties' : {
98+ 'clientId' : {'type' : 'string' },
99+ }
100+ },
101+ 'CreditCreate' : {
102+ 'allOf' : [
103+ {
104+ '$ref' : '#/components/schemas/Credit'
105+ },
106+ {
107+ 'required' : ['clientId' ]
108+ }
109+ ]
110+ }
111+ },
112+ },
113+ }
114+
115+ errors = validator .iter_errors (spec )
116+ errors_list = list (errors )
117+ assert errors_list == []
118+
85119 def test_extra_parameters_in_required (self , validator ):
86120 spec = {
87121 'openapi' : '3.0.0' ,
You can’t perform that action at this time.
0 commit comments