我有一个蓝图,我为此编写了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')
答案 0 :(得分:1)
在@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')