在烧瓶测试中,我创建了一个端点,该端点列出了所有其他端点,就像许多其他端点一样。我可以获取资源类的文档字符串,但是我无法弄清楚如何在资源中获取get / post / put / delete方法的文档字符串。例如,我想记录GET的可用查询参数以及PUT / POST的正文。这就是我所拥有的:
class EndpointListResource(Resource):
"""
List of endpoint descriptions
"""
def get(self):
"""
Generate Endpoints documentation
:return: endpoint list
"""
endpoints = []
for rule in web_app.url_map.iter_rules():
if rule.endpoint in ["static", "api.endpoints"]:
continue
options = {}
for arg in rule.arguments:
options[arg] = "[{0}]".format(arg)
url = url_for(rule.endpoint, **options)
methods = filter(lambda method: method not in ["OPTIONS", "HEAD"], rule.methods)
method_descriptions = map(lambda method: {"method": method, "doc": "?"}, methods)
endpoints.append({
"endpoint": unquote(url),
"doc": web_app.view_functions[rule.endpoint].__doc__,
"methods": list(method_descriptions)
})
return endpoints