Reputation: 136379
I have a Flask REST API. I use healthcheck.EnvironmentDump
to make it easy to dump the environment where my service is running. Is it possible to add the endpoint to the Swagger documentation generated by Restplus?
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')
Upvotes: 2
Views: 662
Reputation: 509
EnvironmentDump and HealthCheck will each install their own handlers for the endpoint, so your get() instances within your defined Resources will not be reached. That being said, providing a stubbed resource is sufficient for it to show up in the Swagger doc generated by Flask-RESTPlus:
health = HealthCheck(app, '/healthcheck')
@api.route('/healthcheck')
class HealthCheckResource(Resource):
def get(self):
pass
Upvotes: 2