Fix 'required' annotations

We lost some required annotations. Add them back in.
pull/977/head
Richard van der Hoff 9 years ago
parent 93eb6fb352
commit 4bdfd3d492

@ -73,7 +73,8 @@ def inherit_parents(obj):
return result return result
def get_json_schema_object_fields(obj, enforce_title=False, include_parents=False): def get_json_schema_object_fields(obj, enforce_title=False, include_parents=False,
mark_required=True):
# Algorithm: # Algorithm:
# f.e. property => add field info (if field is object then recurse) # f.e. property => add field info (if field is object then recurse)
if obj.get("type") != "object": if obj.get("type") != "object":
@ -151,7 +152,7 @@ def get_json_schema_object_fields(obj, enforce_title=False, include_parents=Fals
tables = [fields] tables = [fields]
for key_name in sorted(props): for key_name in props:
logger.debug("Processing property %s.%s", obj.get('title'), key_name) logger.debug("Processing property %s.%s", obj.get('title'), key_name)
value_type = None value_type = None
required = key_name in required_keys required = key_name in required_keys
@ -168,6 +169,7 @@ def get_json_schema_object_fields(obj, enforce_title=False, include_parents=Fals
props[key_name], props[key_name],
enforce_title=True, enforce_title=True,
include_parents=include_parents, include_parents=include_parents,
mark_required=mark_required,
) )
value_type = nested_objects[0]["title"] value_type = nested_objects[0]["title"]
value_id = value_type value_id = value_type
@ -180,6 +182,7 @@ def get_json_schema_object_fields(obj, enforce_title=False, include_parents=Fals
props[key_name]["items"], props[key_name]["items"],
enforce_title=True, enforce_title=True,
include_parents=include_parents, include_parents=include_parents,
mark_required=mark_required,
) )
value_id = nested_objects[0]["title"] value_id = nested_objects[0]["title"]
value_type = "[%s]" % value_id value_type = "[%s]" % value_id
@ -221,24 +224,27 @@ def get_json_schema_object_fields(obj, enforce_title=False, include_parents=Fals
if isinstance(value_type, list): if isinstance(value_type, list):
value_type = " or ".join(value_type) value_type = " or ".join(value_type)
if required and mark_required:
desc = "**Required.** " + desc
fields["rows"].append({ fields["rows"].append({
"key": key_name, "key": key_name,
"type": value_type, "type": value_type,
"id": value_id, "id": value_id,
"required": required, "required": required,
"desc": desc, "desc": desc,
"req_str": "**Required.** " if required else ""
}) })
logger.debug("Done property %s" % key_name) logger.debug("Done property %s" % key_name)
return tables return tables
def get_tables_for_schema(path, schema, include_parents=False): def get_tables_for_schema(path, schema, include_parents=False,
mark_required=True):
resolved_schema = resolve_references(path, schema) resolved_schema = resolve_references(path, schema)
tables = get_json_schema_object_fields(resolved_schema, tables = get_json_schema_object_fields(
resolved_schema,
include_parents=include_parents, include_parents=include_parents,
) mark_required=mark_required)
# the result may contain duplicates, if objects are referred to more than # the result may contain duplicates, if objects are referred to more than
# once. Filter them out. # once. Filter them out.
@ -401,6 +407,7 @@ class MatrixUnits(Units):
schema = good_response["schema"] schema = good_response["schema"]
res_tables = get_tables_for_schema(filepath, schema, res_tables = get_tables_for_schema(filepath, schema,
include_parents=True, include_parents=True,
mark_required=False,
) )
for table in res_tables: for table in res_tables:
if "no-table" not in table: if "no-table" not in table:

Loading…
Cancel
Save