Skip to content

Commit 8e3dc2e

Browse files
authored
Merge pull request #28 from dtkav/allow_lone_required_block_in_allOf
disable required properties checks in allOf blocks
2 parents 615cffe + eb82d74 commit 8e3dc2e

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

openapi_spec_validator/validators.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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

tests/integration/test_validators.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)