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

Always get AssertionError or KeyError in aiohttp #22

Open CMCDragonkai opened 4 years ago

CMCDragonkai commented 4 years ago

I'm using this in aiohttp like:

    api_doc(
        app,
        config_path=(current_dir / "openapi.yaml").as_posix(),
        url_prefix='/',
        title="IAO API"
    )

And the server starts up fine.

But when I visit /. I get:

ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/nix/store/xw8zl3qcl8zha6wi7fns5rzmz2p1mqim-python3.7-aiohttp-3.6.2/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/nix/store/xw8zl3qcl8zha6wi7fns5rzmz2p1mqim-python3.7-aiohttp-3.6.2/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/nix/store/b93vasrvq42s3nhvrhlkjlaz55ji6qn0-python3.7-swagger-ui-py-0.3.0/lib/python3.7/site-packages/swagger_ui/core.py", line 154, in swagger_config_handler
    return web.json_response(self.get_config(request.host))
  File "/nix/store/b93vasrvq42s3nhvrhlkjlaz55ji6qn0-python3.7-swagger-ui-py-0.3.0/lib/python3.7/site-packages/swagger_ui/core.py", line 78, in get_config
    for server in config['servers']:
KeyError: 'servers'

And also:

image

CMCDragonkai commented 4 years ago

Actually I realized it's because of openapi.yaml was not correct.

Wish the error reporting was a bit more obvious.

PWZER commented 2 years ago

@CMCDragonkai I think the validation of openapi.yaml should be done at editing time.