4

因此,按照烧瓶蓝图(https://github.com/rantav/flask-restful-swagger/blob/master/examples/blueprints.py)的 swagger ui 使用示例,我有以下代码:

app = Flask(__name__)
test_blueprint = Blueprint('tests', __name__)
test_api = swagger.docs(restful.Api(test_blueprint), apiVersion='0.1',
                        basePath='http://localhost:5000',
                        produces=["application/json", "text/html"],
                        api_spec_url='/api/spec')

# Operation TestOp defined here
test_api.add_resource(TestOp, '/')

if __name__ == "__main__":
    app.register_blueprint(test_blueprint, url_prefix='/test')
    app.run(debug=True)

但是,当我尝试访问 api 规范文档时,无法找到该 URL。我试过了...

localhost:5000/api/spec
localhost:5000/test_api/api/spec
localhost:5000/test_api

...所有这些都返回 404。我还尝试创建没有蓝图的应用程序,创建文档

swagger.docs(restful.Api(app)...)

反而。完成此操作并且不涉及任何蓝图后,我可以在以下位置找到文档

localhost:5000/api/spec

那么,我是否使用蓝图错误地创建了我的应用程序,或者我只是没有点击正确的 URL 来访问文档?

4

3 回答 3

4

看起来您只是没有点击正确的 URL。因为您的蓝图 url_prefix 是“/test”,所以 Swagger 规范 url 应该位于:

localhost:5000/test/api/spec
于 2014-08-27T15:54:16.540 回答
4

我知道这个线程很旧,但是我今天遇到了这个确切的问题,试图将 flask-restful-swagger 与我的(有点)现代的 flask + python3 应用程序一起使用,该应用程序使用蓝图。同样的问题,没有错误,无论我尝试什么,都没有可用的规范。

我终于放弃了这个包(因为它似乎并没有很活跃),尽管我更喜欢这个包的标记。

我选择了Flasgger,它似乎是最近更新的。在 10 分钟内,我启动并运行了它。代码和简短教程在这里:https ://github.com/rochacbruno/flasgger

于 2016-10-13T15:37:13.500 回答
-1

swagger.docs() 有问题

from flask_restful import Api
test_blueprint = Blueprint('tests', __name__)
test_api = swagger.docs(Api(test_blueprint)...)
app.register_blueprint(test_blueprint)

还有什么

main_blueprint = Blueprint('api', __name__, url_prefix='/demo')
于 2019-02-27T06:20:42.767 回答