in clay/docs.py [0:0]
def clay_docs():
'''
Returns a JSON document describing this service's API
Endpoints are inferred from routes registered with Flask and the docstrings
bound to those methods.
Dialect documentation http://pythonhosted.org/sphinxcontrib-httpdomain/
Swagger documentation https://github.com/wordnik/swagger-core/wiki
:status 200: Generated swagger documentation
:status 500: Something went horribly wrong
'''
headers = {'Content-type': 'application/json'}
response = {
'apiVersion': '0.2',
'swaggerVersion': '1.2',
'basePath': config.get('docs.base_path', None) or request.url_root.rstrip('/'),
'resourcePath': '/',
'apis': [],
'models': {},
}
for rule in app.url_map.iter_rules():
if rule.endpoint == 'static':
continue
api = {
'path': rule.rule,
'operations': [],
}
view_func = app.view_functions[rule.endpoint]
if view_func.__doc__:
docstring = view_func.__doc__.strip('\r\n\t ')
params, responses, stripped_docstring, rtype = parse_docstring(docstring)
shortdoc = [x for x in docstring.split('\n') if x]
if not shortdoc:
shortdoc = 'Undocumented'
else:
shortdoc = shortdoc[0]
else:
shortdoc = 'Undocumented'
params = []
responses = []
stripped_docstring = shortdoc
rtype = None
for http_method in rule.methods:
if http_method in ('HEAD', 'OPTIONS'):
continue
doc = {
'method': http_method,
'nickname': view_func.__name__,
'summary': shortdoc,
'notes': stripped_docstring,
'parameters': params,
'responseMessage': responses,
}
if rtype:
doc['responseClass'] = rtype
model = get_model(rtype)
response['models'][rtype] = model
api['operations'].append(doc)
response['apis'].append(api)