我有一个Flask REST API。我使用healthcheck.EnvironmentDump
使转储服务运行环境变得容易。是否可以将端点添加到Restplus生成的Swagger文档中?
requirements.txt
flask
flask-restplus
gitpython
healthcheck
app.py
#!/usr/bin/env python
"""Simple Flask/Swagger/REST-API example."""
from flask import Flask
from flask_restplus import Resource, Api
from healthcheck import EnvironmentDump
app = Flask(__name__)
api = Api(app, doc='/doc')
# wrap the flask app and give a environment url
# TODO: Add this to API
envdump = EnvironmentDump(app, "/environment")
@api.route('/version')
class VersionAPI(Resource):
def get(self):
import git
repo = git.Repo(search_parent_directories=True)
sha = repo.head.object.hexsha
return sha
@api.route('/health')
class HealthAPI(Resource):
def get(self):
import datetime
return datetime.datetime.now().isoformat()
if __name__ == "__main__":
app.run(host='0.0.0.0')
答案 0 :(得分:1)
EnvironmentDump和HealthCheck将分别为端点安装它们自己的处理程序,因此将无法访问已定义资源中的get()实例。话虽如此,提供存根资源足以使其显示在Flask-RESTPlus生成的Swagger文档中:
setTimeout(()=> {your code here}, 5000);