我正在运行一个flask应用程序,并使用Flasger生成招摇过市的规格以及招摇过市的用户界面。我的API要求使用承载令牌对请求进行身份验证。我可以得到页面上的按钮并设置令牌。但它不是通过请求发送的。我正在使用OpenAPI 3.0.3。下面是我的代码:
from flasgger import Swagger
swagger_template = {
'components': {
'securitySchemes': {
'bearerAuth': {
'type': 'http',
'scheme': 'bearer',
'bearerFormat': 'JWT'
}
},
'security': {
'bearerAuth': []
}
}
}
# Register controllers
api = Api(app)
swagger = Swagger(app=app, config={
'headers': [
],
'title': 'Model Design Application API',
'specs': [
{
'endpoint': 'apispec',
'route': '/apispec.json'
}
],
'openapi': '3.0.3'
}, template=swagger_template)
这是要在Swagger UI中设置的令牌:
这是我大摇大摆地使用的UI:
这是生成的apispec.json:
{
"definitions": {
"User": {
"properties": {
"username": {
"default": "Steven Wilson",
"description": "The name of the user",
"type": "string"
}
}
}
},
"info": {
"description": "powered by Flasgger",
"termsOfService": "/tos",
"title": "Model Design Application API",
"version": "0.0.1"
},
"openapi": "3.0.3",
"paths": {
"/profile": {
"get": {
"description": "It works also with swag_from, schemas and spec_dict<br/>",
"responses": {
"200": {
"description": "A single user item",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"summary": "This examples uses FlaskRESTful Resource"
}
}
},
"security": {
"bearerAuth": []
},
"securitySchemes": {
"bearerAuth": {
"bearerFormat": "JWT",
"scheme": "bearer",
"type": "http"
}
}
}
请给我一些建议。感谢您的帮助
要在Flasger API中添加标头,请执行以下更改:
这里,x-access-token是标题中的密钥名。您可以根据需要更改此名称。 在此之后,我们需要在.yml文件中添加此头文件。我们的.yml文件如下所示:
相关问题 更多 >
编程相关推荐