Flask/Flasgger - документ не отображается, если задан параметр `endpoint`
У меня есть Blueprint, для которого я написал документацию 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')
У вас есть рабочий код, почему вы спросили?
Случай использования для меня, когда у меня есть multi-endpoint только для одной функции, которую я должен определить несколько 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 ответов
Установка конечной точки в @swag_from
также должен содержать имя Blueprint. Пример:@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')