Skip to content

Commit

Permalink
Replaced anyOf with oneOf in digestion_temperature type
Browse files Browse the repository at this point in the history
  • Loading branch information
arschat committed Jan 10, 2025
1 parent 3ecb035 commit 3bb5d31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"digestion_temperature": {
"description": "Temperature of digestion in Celsius or in general terms (i.e. cold, warm, room temperature).",
"anyOf": [
"oneOf": [
{
"type": "number"
},
Expand Down
18 changes: 9 additions & 9 deletions src/human_readable_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ def generateMarkdown(self, schemas, entity_type):
# if link is not "":
# print(schema["title"] + "\t "+ property + "\t"+ link)

# add type values if anyOf values are there
anyOf_types = [t['type'] for t in schema['properties'][property]['anyOf'] if 'type' in t.keys()] if 'anyOf' in schema['properties'][property].keys() else []
schema['properties'][property]['type'] = ' or '.join(anyOf_types) if 'type' not in schema['properties'][property].keys() else schema['properties'][property]['type']
anyOf_enum = []
if 'anyOf' in schema['properties'][property].keys():
for t in schema['properties'][property]['anyOf']:
# add type values if oneOf values are there
oneOf_types = [t['type'] for t in schema['properties'][property]['oneOf'] if 'type' in t.keys()] if 'oneOf' in schema['properties'][property].keys() else []
schema['properties'][property]['type'] = ' or '.join(oneOf_types) if 'type' not in schema['properties'][property].keys() else schema['properties'][property]['type']
oneOf_enum = []
if 'oneOf' in schema['properties'][property].keys():
for t in schema['properties'][property]['oneOf']:
if 'enum' in t.keys():
anyOf_enum.extend(t['enum'])
if anyOf_enum:
schema['properties'][property]['enum'] = anyOf_enum if 'enum' not in schema['properties'][property].keys() else schema['properties'][property]['enum']
oneOf_enum.extend(t['enum'])
if oneOf_enum:
schema['properties'][property]['enum'] = oneOf_enum if 'enum' not in schema['properties'][property].keys() else schema['properties'][property]['enum']

if "enum" in schema["properties"][property]:
enum_values = ", ".join(str(enum) for enum in schema["properties"][property]["enum"])
Expand Down
10 changes: 5 additions & 5 deletions src/schema_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# Property attributes

property_attributes = ['description', 'type', 'pattern', 'example', 'enum', '$ref', 'user_friendly', 'items', 'guidelines', 'format', 'comment', 'maximum', 'minimum', 'oneOf', 'anyOf', 'bionetworks']
property_attributes = ['description', 'type', 'pattern', 'example', 'enum', '$ref', 'user_friendly', 'items', 'guidelines', 'format', 'comment', 'maximum', 'minimum', 'oneOf', 'oneOf', 'bionetworks']

ontology_attributes = ['graph_restriction', 'ontologies', 'classes', 'relations', 'direct', 'include_self']

Expand Down Expand Up @@ -140,14 +140,14 @@ def lintSchema(self, path, ols_api):
errors.append(schema_filename + ".json: Keyword `user_friendly` missing from property `" + property + "`.")

# Property must contain type attribute
anyOf_types = [t['type'] for t in properties[property]['anyOf'] if 'type' in t.keys()] if \
'anyOf' in properties[property].keys() else []
if 'type' not in properties[property].keys() and not anyOf_types:
oneOf_types = [t['type'] for t in properties[property]['oneOf'] if 'type' in t.keys()] if \
'oneOf' in properties[property].keys() else []
if 'type' not in properties[property].keys() and not oneOf_types:
errors.append(schema_filename + ".json: Keyword `type` missing from property `" + property + "`.")

else:
# assign type value to the property key
properties[property]['type'] = anyOf_types if 'type' not in properties[property].keys() else properties[property]['type']
properties[property]['type'] = oneOf_types if 'type' not in properties[property].keys() else properties[property]['type']
# change property to list to test all values of array
properties[property]['type'] = properties[property]['type'] if isinstance(properties[property]['type'], list) else [properties[property]['type']]

Expand Down

0 comments on commit 3bb5d31

Please sign in to comment.