2

I have a Blueprint which I wrote an OpenAPI documentation for. Without the endpoint definition, it's working just fine but it doesn't with the endpoint definition.

Working code:

@my_blueprint.route('/')
@swag_from('open_api/root.yml')
def main():
    return str('This is the root api')

Not Working (notice how I defined the endpoint in parameters):

@my_blueprint.route('/', endpoint='foo')
@swag_from('open_api/root.yml', endpoint='foo')
def main():
    return str('This is the root api')

You have working code, why'd you ask?

The use case for me is when I have multi-endpoint for just a single function which I have to define multiple yml file for each docs.

@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')
Michael 'Maik' Ardan
  • 4,213
  • 9
  • 37
  • 60

1 Answers1

2

Setting an endpoint in @swag_from should also contain the name of the Blueprint. Example: @swag_from('my_yaml.yml', endpoint='{}.your_endpoint'.format(my_blueprint.name))

Full example:

@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')
stasiekz
  • 1,775
  • 5
  • 22
Michael 'Maik' Ardan
  • 4,213
  • 9
  • 37
  • 60