Flask 如何在Flasger中注册Swagger端点
目前正在使用Swagger/Flasger/Flask在应用程序中记录API/路由Flask 如何在Flasger中注册Swagger端点,flask,swagger,openapi,flasgger,Flask,Swagger,Openapi,Flasgger,目前正在使用Swagger/Flasger/Flask在应用程序中记录API/路由 #app.py 从烧瓶进口烧瓶 从Flasger进口大摇大摆 从myapp.blueprints.main导入main app=烧瓶(名称) 应用程序注册蓝图(主) 炫耀=炫耀(应用程序) #myapp.blueprints.main.views.py main=Blueprint('main',_名称__) @main.route('/user/',方法=['GET','PUT','DELETE']) @ma
#app.py
从烧瓶进口烧瓶
从Flasger进口大摇大摆
从myapp.blueprints.main导入main
app=烧瓶(名称)
应用程序注册蓝图(主)
炫耀=炫耀(应用程序)
#myapp.blueprints.main.views.py
main=Blueprint('main',_名称__)
@main.route('/user/',方法=['GET','PUT','DELETE'])
@main.route('/user',methods=['GET','POST'])
def用户(用户id=无):
通过
要获取用于同一功能的两条路线的文档,我需要在每个路线上做两件事:
@swag\u
@main.route
和@swag\u从
赋予相同的端点
kwarg#myapp.blueprints.main.views.py
@main.route('/user/',方法=['GET','PUT','DELETE'])
@main.route('/user',methods=['GET','POST'])
@swag_from('user_,不带id.yml'))
def用户(用户id=无):
通过
/>curl localhost:8000/apispec_1.json
{
“定义”:{
“用户”:{
“财产”:{
“年龄”:{
“默认值”:“180”,
“说明”:“用户年龄(应为整数)”,
“类型”:“整数”
},
“标签”:{
“默认值”:[
“巫师”,
“霍格沃茨”,
“死了”
],
“说明”:“可选标签列表”,
“项目”:{
“类型”:“字符串”
},
“类型”:“数组”
},
“用户名”:{
“默认值”:“天狼星黑”,
“说明”:“用户名”,
“类型”:“字符串”
}
},
“必需”:[
“用户名”,
“年龄”
]
}
},
“信息”:{
“说明”:“测试招摇过市api规范”,
“服务条款”:“/tos”,
“标题”:“测试招摇过市api”,
“版本”:“1.0”
},
“路径”:{
“/user”:{
“获取”:{
“说明”:“默认负载无效,请重试,然后将年龄更改为有效整数,然后重试
”,
“参数”:[
{
“in”:“body”,
“姓名”:“正文”,
“必需”:正确,
“模式”:{
$ref:“#/definitions/User”
}
}
],
“答复”:{
"200": {
“说明”:“单用户项目”,
“模式”:{
$ref:“#/definitions/User”
}
}
},
“总结”:“使用JsonSchema进行测试验证”
},
“职务”:{
“说明”:“默认负载无效,请重试,然后将年龄更改为有效整数,然后重试
”,
“参数”:[
{
“in”:“body”,
“姓名”:“正文”,
“必需”:正确,
“模式”:{
$ref:“#/definitions/User”
}
}
],
“答复”:{
"200": {
“说明”:“单用户项目”,
“模式”:{
$ref:“#/definitions/User”
}
}
},
“总结”:“使用JsonSchema进行测试验证”
}
},
“/user/{user_id}”:{
“获取”:{
“说明”:“默认负载无效,请重试,然后将年龄更改为有效整数,然后重试
”,
“参数”:[
{
“in”:“body”,
“姓名”:“正文”,
“必需”:正确,
“模式”:{
$ref:“#/definitions/User”
}
}
],
“答复”:{
"200": {
“说明”:“单用户项目”,
“模式”:{
$ref:“#/definitions/User”
}
}
},
“总结”:“使用JsonSchema进行测试验证”
}
}
},
“招摇过市”:“2.0”
}
但是,只要我添加端点
和方法
kwargs,我的输出就会丢失规范:
#myapp.blueprints.main.views.py
@main.route('/user/',方法=['GET','PUT','DELETE'])
@main.route('/user',endpoint='my-new-endpoint',methods=['GET','POST'])
@swag_from('user_不带_id.yml',endpoint='my-new-endpoint',methods=['GET','POST']))
def用户(用户id=无):
通过
/>curl localhost:8000/apispec_1.json
{
“定义”:{},
“信息”:{
“说明”:“测试招摇过市api规范”,
“服务条款”:“/tos”,
“标题”:“测试招摇过市api”,
“版本”:“1.0”
},
“路径”:{},
“招摇过市”:“2.0”
}
不确定文档要放在哪里。Flasger's没有展示如何使这项工作与之配合。
@swag\u from
需要在其端点
字段中包含蓝图名称,不幸的是,这在flasger
文档中不清楚
# myapp.blueprints.main.views.py
@main.route('/user/<path:user_id>', methods=['GET', 'PUT', 'DELETE'])
@main.route('/user', endpoint='my-new-endpoint', methods=['GET', 'POST'])
@swag_from('user_without_id.yml', endpoint='main.my-new-endpoint', methods=['GET', 'POST'])
def user(user_id=None):
pass
#myapp.blueprints.main.views.py
@main.route('/user/',方法=['GET','PUT','DELETE'])
@main.route('/user',endpoint='my-new-endpoint',methods=['GET','POST'])
@swag_from('user_不带_id.yml',endpoint='main.my new endpoint',methods=['GET','POST']))
def用户(用户id=无):
通过