IndominusByte / fastapi-jwt-auth

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)
http://indominusbyte.github.io/fastapi-jwt-auth/
MIT License
627 stars 143 forks source link

Non unique operation_id can lead to documentation bug #71

Open DJM-FDC opened 2 years ago

DJM-FDC commented 2 years ago

In https://indominusbyte.github.io/fastapi-jwt-auth/advanced-usage/generate-docs/ it is recommended to use @app.get('/protected', operation_id="authorize") and later identify the route/endpoint with router_authorize = [route for route in app.routes[4:] if route.operation_id == "authorize"]. This means the operation_id is not unique, which is warned against by https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/.

Making it not unique resulted in a bug in the documentation where all endpoints with the jwt-auth expanded at once, when clicked on.

We fixed it by expanding the for loop below and using an exclude list instead of the operation_id for route in app.routes[4:]: if route.path in ["/excluded", "/endpoint"]: continue Adding a unique bit to the operation_id and using in also works