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