Improve upon the transaction schema and examples

Reduces data duplication and makes the objects more reusable for other areas of the spec
This commit is contained in:
Travis Ralston 2018-07-12 21:34:52 -06:00
parent 374ec00046
commit e5da1e1741
8 changed files with 196 additions and 178 deletions

View file

@ -138,6 +138,10 @@ def inherit_parents(obj):
Recurse through the 'allOf' declarations in the object
"""
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", [])
if not parents:
return obj
@ -379,6 +383,10 @@ def get_tables_for_response(schema):
def get_example_for_schema(schema):
"""Returns a python object representing a suitable example for this object"""
schema = inherit_parents(schema)
if isinstance(schema, list):
return [get_example_for_schema(v) for v in schema]
if 'example' in schema:
example = schema['example']
return example
@ -398,7 +406,10 @@ def get_example_for_schema(schema):
if proptype == 'array':
if 'items' not in schema:
raise Exception('"array" property has neither items nor example')
return [get_example_for_schema(schema['items'])]
result = get_example_for_schema(schema['items'])
if isinstance(result, list):
return result
return [result]
if proptype == 'integer':
return 0