简体   繁体   中英

Is there a way to introduce Swagger automated documentation into a solution that uses Flask Bluperints?

I would like to introduce Swagger documentation to a project I built using Flask and Blueprints, but I couldn't find a way to do so.

eg

from flask import Flask, Blueprint

class HealthController():
   def __init__(self):
      self.blueprint = self.define_routes()

   def define_routes(self):
      blueprint = Blueprint('health', __name__)
      @blueprint.route('/api/health', methods=['GET'])
      def health():
         return flask.jsonify({"result": True}), 200
      return blueprint

application = Flask(__name__)
application.register_blueprint(HealthController().blueprint)
application.run()

How do I introduce a flasgger or any other framework generating Swagger UI while sticking to Flask and Blueprints?

I've tried using flask-openapi3, flassger and searching around but so far, I could not find the solution :(

Apparently apiflask works perfectly well with the blueprints. All you have to do is to follow the manual and replace Blueprint class from Flask with APIBlueprint from apiflask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM