3 # gen_api_method_docs.py
5 # Generate docs for Arvados methods.
7 # This script will retrieve the discovery document at
8 # https://localhost:9900/discovery/v1/apis/arvados/v1/rest
9 # and will generate Textile documentation files in the current
17 r = requests.get('https://localhost:9900/discovery/v1/apis/arvados/v1/rest',
19 if r.status_code != 200:
20 raise Exception('Bad status code %d: %s' % (r.status_code, r.text))
22 if 'application/json' not in r.headers.get('content-type', ''):
23 raise Exception('Unexpected content type: %s: %s' %
24 (r.headers.get('content-type', ''), r.text))
29 for resource in sorted(api[u'resources']):
30 resource_num = resource_num + 1
31 out_fname = resource + '.textile'
32 if os.path.exists(out_fname):
33 print "PATH EXISTS ", out_fname
35 outf = open(out_fname, 'w')
42 navorder: {resource_num}
47 Required arguments are displayed in %{{background:#ccffcc}}green%.
49 """.format(resource_num=resource_num, resource=resource))
51 methods = api['resources'][resource]['methods']
52 for method in sorted(methods.keys()):
53 methodinfo = methods[method]
62 table(table table-bordered table-condensed).
63 |_. Argument |_. Type |_. Description |_. Location |_. Example |
65 method=method, description=methodinfo['description']))
69 for param, paraminfo in methodinfo['parameters'].iteritems():
70 paraminfo.setdefault(u'description', '')
71 paraminfo.setdefault(u'location', '')
73 if paraminfo.get('minimum', '') or paraminfo.get('maximum', ''):
74 limit = "range {0}-{1}".format(
75 paraminfo.get('minimum', ''),
76 paraminfo.get('maximum', 'unlimited'))
77 if paraminfo.get('default', ''):
80 limit = limit + 'default %d' % paraminfo['default']
82 paraminfo['type'] = '{0} ({1})'.format(
83 paraminfo['type'], limit)
85 row = "|{param}|{type}|{description}|{location}||\n".format(
86 param=param, **paraminfo)
87 if paraminfo.get('required', False):
90 notrequired.append(row)
92 for row in sorted(required):
93 outf.write("{background:#ccffcc}." + row)
94 for row in sorted(notrequired):
97 # pprint.pprint(methodinfo)
100 print "wrote ", out_fname