Improve handing of lists appearing in items
This commit is contained in:
parent
88beaf4ad8
commit
a4e5a461f9
1 changed files with 8 additions and 9 deletions
|
@ -140,9 +140,6 @@ def inherit_parents(obj):
|
||||||
"""
|
"""
|
||||||
logger.debug("inherit_parents %r" % obj)
|
logger.debug("inherit_parents %r" % obj)
|
||||||
|
|
||||||
if isinstance(obj, list):
|
|
||||||
return [inherit_parents(obj[i]) for i in range(0, len(obj))]
|
|
||||||
|
|
||||||
parents = obj.get("allOf", [])
|
parents = obj.get("allOf", [])
|
||||||
if not parents:
|
if not parents:
|
||||||
return obj
|
return obj
|
||||||
|
@ -298,6 +295,8 @@ def process_data_type(prop, required=False, enforce_title=True):
|
||||||
|
|
||||||
elif prop_type == "array":
|
elif prop_type == "array":
|
||||||
items = prop["items"]
|
items = prop["items"]
|
||||||
|
# Items can be a list of schemas or a schema itself
|
||||||
|
# http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.4
|
||||||
if isinstance(items, list):
|
if isinstance(items, list):
|
||||||
prop_title = "["
|
prop_title = "["
|
||||||
for i in items:
|
for i in items:
|
||||||
|
@ -385,9 +384,6 @@ def get_example_for_schema(schema):
|
||||||
"""Returns a python object representing a suitable example for this object"""
|
"""Returns a python object representing a suitable example for this object"""
|
||||||
schema = inherit_parents(schema)
|
schema = inherit_parents(schema)
|
||||||
|
|
||||||
if isinstance(schema, list):
|
|
||||||
return [get_example_for_schema(v) for v in schema]
|
|
||||||
|
|
||||||
if 'example' in schema:
|
if 'example' in schema:
|
||||||
example = schema['example']
|
example = schema['example']
|
||||||
return example
|
return example
|
||||||
|
@ -407,10 +403,13 @@ def get_example_for_schema(schema):
|
||||||
if proptype == 'array':
|
if proptype == 'array':
|
||||||
if 'items' not in schema:
|
if 'items' not in schema:
|
||||||
raise Exception('"array" property has neither items nor example')
|
raise Exception('"array" property has neither items nor example')
|
||||||
result = get_example_for_schema(schema['items'])
|
items = schema['items']
|
||||||
|
if isinstance(items, list):
|
||||||
|
return [get_example_for_schema(i) for i in items]
|
||||||
|
result = get_example_for_schema(items)
|
||||||
if isinstance(result, list):
|
if isinstance(result, list):
|
||||||
return result
|
|
||||||
return [result]
|
return [result]
|
||||||
|
return result
|
||||||
|
|
||||||
if proptype == 'integer':
|
if proptype == 'integer':
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue