Skip to content
Open
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
48 changes: 24 additions & 24 deletions openMINDS_validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,40 @@ def check_required(self):
"""
Validates required properties against the properties defined in the schema definition.
"""
def load_schema(path):
def load_schema(path, parent_path=None):
if path.startswith("/"):
return fetch_remote_schema_extends(path, self.version_file, self.openMINDS_build_version)
return load_json(f'./schemas/{path}')

def _check_required_extends(extends_path, required_property):
schema = load_schema(extends_path)
if required_property not in schema['properties']:
if '_extends' in schema:
return _check_required_extends(schema['_extends'], required_property)
logging.error(f'Missing required property "{required_property}" in the schema definition.')
return

def _retrieve_inherited_required_properties(extends_path):
schema = load_schema(extends_path)
inherited_properties_required = schema.get('required', [])
if parent_path:
parent_dir = "/".join(parent_path.split("/")[:3])
return fetch_remote_schema_extends(f"{parent_dir}/{path}", self.version_file, self.openMINDS_build_version)
return load_json(f'./schemas/{path}'), None

def collect_inherited(extends_path, parent_path=None):
schema = load_schema(extends_path, parent_path)
if schema is None:
logging.error(f'Missing parent schema "{extends_path}".')
return [], {}
required = schema.get('required', [])
properties = schema.get('properties', {})
if '_extends' in schema:
inherited_properties_required.extend(_retrieve_inherited_required_properties(schema['_extends']))
return inherited_properties_required
inherited_required, inherited_properties = collect_inherited(schema['_extends'], extends_path)
required.extend(inherited_required)
properties.update(inherited_properties)
return required, properties

if 'required' not in self.schema:
return
if '_type' not in self.schema and '_extends' not in self.schema:
if 'required' not in self.schema or ('_type' not in self.schema and '_extends' not in self.schema):
return

required_properties = self.schema.get('required', [])
all_properties = dict(self.schema.get('properties', {}))

if '_extends' in self.schema:
required_properties.extend(_retrieve_inherited_required_properties(self.schema['_extends']))
inherited_required, inherited_properties = collect_inherited(self.schema['_extends'])
required_properties.extend(inherited_required)
all_properties.update(inherited_properties)

for required_property in required_properties:
if required_property not in self.schema['properties'].keys():
if '_extends' in self.schema:
_check_required_extends(self.schema['_extends'], required_property)
continue
if required_property not in all_properties:
logging.error(f'Missing required property "{required_property}" in the schema definition.')

def validate(self):
Expand Down