如何调整 flasgger 以便在发送请求时使用基本身份验证

How to tune flasgger in order to use basic authentication in sending requests

我尝试在我的简单 RESTful API 中使用 flasgger。 API 需要 authentication/authorization 并使用基本身份验证来执行任何查询。

swagger.io 中有关于基本身份验证的非常好的文档 但是这些设置如何在 flassger 中实现呢?我尝试使用模板将 securityDefinitions 设置为 swaggler,但尝试尚未成功。

更新。应该是问题还没有解决。 Flasgger doesnt support basic auth #103

我已经解决了添加下一个代码的身份验证问题:

swagger_template = {
    # Other settings

    'securityDefinitions': {
        'basicAuth': {
            'type': 'basic'
        }
    },

    # Other settings
}

app = Flask(__name__)
Swagger(app, swagger_config, template=swagger_template)

感谢Dimaf的回答,对我帮助很大。只想更新新版本,以防其他人运行遇到同样的问题。

对于Swagger 3.0,更新配置如下(本例为bearer授权):

swagger_template = {
    "components": {
        "securitySchemes": {
            "BearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "JWT",
                "in": "header",
            }
        }
    }
}