Flask/Flasgger - 如果设置了 `endpoint` 参数,文档不会出现
Flask/Flasgger - Document does not appear if `endpoint` parameter is set
我有一个蓝图,我为其编写了一个 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')
我有一个蓝图,我为其编写了一个 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')