jibrelnetwork / jibrel-aiohttp-swagger

Swagger UI plugin for aiohttp
2 stars 0 forks source link

pyyaml 6.0 breaks loading of yaml files #4

Open OysteinBrandt opened 2 years ago

OysteinBrandt commented 2 years ago

Description

Tried to render Swagger UI for my service at the /api/doc/ endpoint.

What happened

Swagger IU renders Internal Server Error (Failed to load API definition).

What went wrong

Loading of yaml file fails because of breaking changes in PyYAML 6.0.

Expected to happen

Provided yaml is rendered in Swagger UI.

What I Did

[29/Nov/2021:13:28:52 +0000] "GET /api/doc/ HTTP/1.1" 200 2046 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
[ERROR] load() missing 1 required positional argument: 'Loader'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp_middlewares/error.py", line 208, in middleware
    return await handler(request)
  File "/usr/local/lib/python3.8/site-packages/jibrel_aiohttp_swagger/handlers.py", line 11, in spec_handler
    json_content = load_spec_file(spec_path)
  File "/usr/local/lib/python3.8/site-packages/jibrel_aiohttp_swagger/utils.py", line 29, in _wrapped
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/jibrel_aiohttp_swagger/utils.py", line 39, in load_spec_file
    content = yaml.load(fp)
TypeError: load() missing 1 required positional argument: 'Loader'

Related issue at PyYAML

https://github.com/yaml/pyyaml/issues/576

OysteinBrandt commented 2 years ago

A temporary workaround is to set a fixed version of pyyaml in your requirements file. I.e. pyyaml ~= 5.4.1 Then the Swagger UI renders as expected.

Log output:

[29/Nov/2021:15:49:00 +0000] "GET /api/doc/ HTTP/1.1" 200 2046 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
/usr/local/lib/python3.8/site-packages/jibrel_aiohttp_swagger/utils.py:39: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  content = yaml.load(fp)