Aemilius
Aemilius

Reputation: 21

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.

e.g.

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 :(

Upvotes: 1

Views: 1150

Answers (1)

Aemilius
Aemilius

Reputation: 21

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.

Upvotes: 1

Related Questions