如何在通过带有蓝图的flask restplus生成的swagger.json中创建主机字段

时间:2018-07-26 19:21:33

标签: python flask swagger flask-restplus

我创建了一个flask应用程序,如下所示。在本地,我可以看到Swagger UI;但是,当部署到服务器时,Swagger UI不可用(继续出现错误“ SCRIPT5009:SCRIPT5009:未定义'SwaggerUIBundle'”)。即使Swagger.json处于url_prefix级别,看来swagger也在根URL级别(本地主机或服务器,而不是url_prefix级别)寻找文件。

app = Flask(__name__)
blueprint = Blueprint('queue', __name__, url_prefix='/apipath/api/v1'
authorizations = {
'apikey': {
    'type': 'apiKey',
    'in': 'header',
    'name': 'X-Api-Key'
  }
}
api = Api(blueprint, version='1.0.0', title='title', description='description', contact='email', authorizations=authorizations, doc='/')
app.register_blueprint(blueprint)
ns = api.namespace('queue', description='description')

因此,我决定使用生成的Swagger.json。但是,Swagger.json没有host字段,因此内置的Swagger UI无法正常工作(这意味着我无法“尝试一下”),如下所示。

swagger "2.0"
basePath    "/apipath/api/v1"
paths   
    /queueprediction    
        post    
            responses   
                200 

1 个答案:

答案 0 :(得分:0)

我想出了如何在Swagger.json中包含host字段。

通过设置app.config ['SERVER_NAME'] ='某些主机'而不在app.run语句中设置'host'或'port'可以达到目的。

谢谢!

相关问题