简体   繁体   English

有没有办法将 Swagger 自动化文档引入使用 Flask Bluperints 的解决方案中?

[英]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.我想将 Swagger 文档介绍给我使用 Flask 和蓝图构建的项目,但我找不到这样做的方法。

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?如何在坚持使用 Flask 和蓝图的同时引入flasgger或任何其他生成 Swagger UI 的框架?

I've tried using flask-openapi3, flassger and searching around but so far, I could not find the solution :(我已经尝试使用flask-openapi3、flassger 并四处搜索,但到目前为止,我找不到解决方案:(

Apparently apiflask works perfectly well with the blueprints.显然apiflask与蓝图完美配合。 All you have to do is to follow the manual and replace Blueprint class from Flask with APIBlueprint from apiflask.您所要做的就是按照手册将 Flask 中的Blueprint类替换为APIBlueprint中的 APIBlueprint。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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