swagger-ui-py icon indicating copy to clipboard operation
swagger-ui-py copied to clipboard

Always get AssertionError or KeyError in aiohttp

Open CMCDragonkai opened this issue 5 years ago • 2 comments

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 avatar Aug 14 '20 06:08 CMCDragonkai

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

Wish the error reporting was a bit more obvious.

CMCDragonkai avatar Aug 14 '20 06:08 CMCDragonkai

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

PWZER avatar Sep 27 '21 06:09 PWZER