Authentication router with OAuth2PasswordRequestForm dependency route breaks /docs when included inside startup event #292
Unanswered
richardnm-2
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I was adding a security layer on an app that I was working on and had already tested basic functionality deployed into Lambda. I'm using a container image.
When I added my security layer that I borrowed from another app running on a live server, my app still worked when making requests to it, but the
/docsroute started to throw an error:Failed to load API definition
Fetch error. Internal server error /openapi.json.
I dynamically include my routers to my app instance using
app.include_routers(), and I did it inside thestartupevent.Local testing done, all tests passed, the frontend still worked as expected but the
/docswere gone.I narrowed the error down to the imports being performed inside the
startupevent, but only when I have theOAuth2PasswordRequestFormdependency.Here is a minimal reproducible example, using the non-annotaded example in the FastAPI (v0.95) documentation
Removing the
OAuth2PasswordRequestFormdependency, the/docswork again, and including the routers outside of thestartupevent also.Maybe I missed something regarding lifespans. Also have the same structure running on another project under
Nginx, and the pattern works.It's not actually a big deal to include the
routersoutside the event, but I wonder why this conflicts with the OAuth2PasswordRequestForm.All reactions