fecgov / fecfile-web-api

Back-end API for FECfile application
Other
8 stars 2 forks source link

feature/1506 - reinstate and fix swagger api docs generation #1014

Closed dheitzer closed 2 months ago

dheitzer commented 3 months ago

https://fecgov.atlassian.net/browse/FECFILE-1506

Issue was that the DotFECRenderer didn't define 'format' which was causing swagger to blow up when it expected it here

fecfile-api              | │ /usr/local/lib/python3.10/site-packages/drf_spectacular/openapi.py:1169 in <listcomp>            │
fecfile-api              | │                                                                                                  │
fecfile-api              | │   1166 │   │   │   │   return not isinstance(r, renderers.BrowsableAPIRenderer)                  │
fecfile-api              | │   1167 │   │                                                                                     │
fecfile-api              | │   1168 │   │   return list(dict.fromkeys([                                                       │
fecfile-api              | │ ❱ 1169 │   │   │   getattr(r, attribute).split(';')[0]                                           │
fecfile-api              | │   1170 │   │   │   for r in self.view.get_renderers()                                            │
fecfile-api              | │   1171 │   │   │   if use_renderer(r) and hasattr(r, attribute)                                  │
fecfile-api              | │   1172 │   │   ]))                                                                               │
fecfile-api              | │                                                                                                  │
fecfile-api              | │ ╭────────────────────────────────────────── locals ──────────────────────────────────────────╮   │
fecfile-api              | │ │           .0 = <list_iterator object at 0x7f736d433f70>                                    │   │
fecfile-api              | │ │    attribute = 'format'                                                                    │   │
fecfile-api              | │ │            r = <fecfiler.web_services.renderers.DotFECRenderer object at 0x7f736d433f10>   │   │
fecfile-api              | │ │ use_renderer = <function AutoSchema.map_renderers.<locals>.use_renderer at 0x7f73733ca200> │   │
fecfile-api              | │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯   │
fecfile-api              | ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
fecfile-api              | AttributeError: 'NoneType' object has no attribute 'split'

According to BaseRenderer: All renderers should extend this class, setting the media_type and format attributes, and override the .render() method. so swagger is fine to expect it.

As far as I can tell, format is only metadata and does not affect functionality, so setting it shouldn't cause any issues.