PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
68 stars 31 forks source link

Set the landing page to root `/` #15

Open pasqLisena opened 4 years ago

pasqLisena commented 4 years ago

When I try to setup swagger to serve the UI from root / (rather than /api/docs):

api_doc(app, config_path='swagger.yml', url_prefix='', title='API title')

I get the following error:

Traceback (most recent call last):
  File "app/run.py", line 1, in <module>
    from project import app
  File "/Users/pasquale/git/ted-talk-topic-extraction/app/project.py", line 16, in <module>
    api_doc(app, config_path='swagger.yml', url_prefix='/', title='Topic Model API')
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/old.py", line 25, in __init__
    super(FlaskInterface, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/core.py", line 33, in __init__
    getattr(self, '_{}_handler'.format(app_type))()
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/core.py", line 142, in _flask_handler
    self._app.register_blueprint(swagger_blueprint)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 98, in wrapper_func
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1168, in register_blueprint
    blueprint.register(self, options, first_registration)
  File "/usr/local/lib/python3.7/site-packages/flask/blueprints.py", line 257, in register
    deferred(state)
  File "/usr/local/lib/python3.7/site-packages/flask/blueprints.py", line 295, in <lambda>
    self.record(lambda s: s.add_url_rule(rule, endpoint, view_func, **options))
  File "/usr/local/lib/python3.7/site-packages/flask/blueprints.py", line 87, in add_url_rule
    **options
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 98, in wrapper_func
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1275, in add_url_rule
    rule = self.url_rule_class(rule, methods=methods, **options)
  File "/usr/local/lib/python3.7/site-packages/werkzeug/routing.py", line 666, in __init__
    raise ValueError("urls must start with a leading slash")
ValueError: urls must start with a leading slash
CMCDragonkai commented 4 years ago

I don't get this with aiohttp. But I get a different error #22

PWZER commented 2 years ago

@pasqLisena This is Flask requirements, you should set url_prefix non-empty, It has nothing to do with this project.