in server/api/plugins/openapi.py [0:0]
def dumpExamples(self, pdef, array = False):
schema = None
if 'schema' in pdef:
if 'type' in pdef['schema'] and pdef['schema']['type'] == 'array':
array = True
schema = pdef['schema']['items']['$ref']
else:
schema = pdef['schema']['$ref']
if '$ref' in pdef:
schema = pdef['$ref']
if schema:
# #/foo/bar/baz --> dict['foo']['bar']['baz']
pdef = functools.reduce(operator.getitem, schema.split('/')[1:], self.API)
js = {}
desc = {}
if 'properties' in pdef:
for k, v in pdef['properties'].items():
if 'description' in v:
desc[k] = [v['type'], v['description']]
if 'example' in v:
js[k] = v['example']
elif 'items' in v:
if v['type'] == 'array':
js[k], foo = self.dumpExamples(v['items'], True)
else:
js[k], foo = self.dumpExamples(v['items'])
return [js if not array else [js], desc]