python-3.x - Flask/Flasgger - 如果设置了 `endpoint` 参数,文档不会出现
问题描述
我有一个蓝图,我为其编写了 OpenAPI 文档。没有端点定义,它工作得很好,但它没有端点定义。
工作代码:
@my_blueprint.route('/')
@swag_from('open_api/root.yml')
def main():
return str('This is the root api')
不工作(注意我如何在参数中定义端点):
@my_blueprint.route('/', endpoint='foo')
@swag_from('open_api/root.yml', endpoint='foo')
def main():
return str('This is the root api')
你有工作代码,你为什么要问?
对我来说,用例是当我只有一个函数的多端点时,我必须yml
为每个文档定义多个文件。
@my_blueprint.route('/', endpoint='foo')
@my_blueprint.route('/<some_id>', endpoint='foo_with_id')
@swag_from('open_api/root.yml', endpoint='foo')
@swag_from('open_api/root_with_id.yml', endpoint='foo_with_id')
def main(some_id):
if (some_id):
return str('Here's your ID')
return str('This is the root api')
解决方案
设置端点@swag_from
还应包含蓝图的名称。例子:@swag_from('my_yaml.yml', endpoint='{}.your_endpoint'.format(my_blueprint.name))
完整示例:
@my_blueprint.route('/', endpoint='foo') # endpoint is foo
@my_blueprint.route('/<some_id>', endpoint='foo_with_id') # endpoint is foo_with_id
@swag_from('open_api/root.yml', endpoint='{}.foo'.format(my_blueprint.name)) # blueprint is set as the prefix for the endpoint
@swag_from('open_api/root_with_id.yml', endpoint='{}.foo_with_id'.format(my_blueprint.name)) # same goes here
def main(some_id):
if (some_id):
return str("Here's your ID")
return str('This is the root api')
推荐阅读
- pyspark - aws 胶水 pyspark 删除数组中的结构,但保留数据并保存到 dynamodb
- c# - C# 类:非静态字段、方法或属性需要对象引用
- javascript - 默认情况下如何使用javascript扩展第三个菜单及其子菜单项
- tensorflow - 如何理解教程中的位置编码实现?
- javascript - 比较两个数组并替换/合并另一个数组(js)中存在的 id 值
- mysql - “信函请求”系统的理想sql数据库结构
- python - 如何将我的 python 代码连接到 Internet 上托管的 mysql 数据库?
- java - 使用 (a,b) -> ab lambda 函数 java
- java - 在父/子仓库中配置 maven 插件的正确方法
- ethereum - 调用传递函数时会发生重入吗?