Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions openapi_spec_validator/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,21 @@ class SchemaValidator(object):
def __init__(self, dereferencer):
self.dereferencer = dereferencer

def iter_errors(self, schema):
def iter_errors(self, schema, require_properties=True):
schema_deref = self.dereferencer.dereference(schema)

if 'allOf' in schema_deref:
for inner_schema in schema_deref['allOf']:
for err in self.iter_errors(inner_schema):
for err in self.iter_errors(
inner_schema,
require_properties=False
):
yield err

required = schema_deref.get('required', [])
properties = schema_deref.get('properties', {}).keys()
extra_properties = list(set(required) - set(properties))
if extra_properties:
if extra_properties and require_properties:
yield ExtraParametersError(
"Required list has not defined properties: {0}".format(
extra_properties
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ def test_same_parameters_names(self, validator):
errors_list = list(errors)
assert errors_list == []

def test_allow_allof_required_no_properties(self, validator):
spec = {
'openapi': '3.0.0',
'info': {
'title': 'Test Api',
'version': '0.0.1',
},
'paths': {},
'components': {
'schemas': {
'Credit': {
'type': 'object',
'properties': {
'clientId': {'type': 'string'},
}
},
'CreditCreate': {
'allOf': [
{
'$ref': '#/components/schemas/Credit'
},
{
'required': ['clientId']
}
]
}
},
},
}

errors = validator.iter_errors(spec)
errors_list = list(errors)
assert errors_list == []

def test_extra_parameters_in_required(self, validator):
spec = {
'openapi': '3.0.0',
Expand Down