Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 per controller middlewares and exception handlers #6

Open
lucas-labs opened this issue Nov 19, 2023 · 0 comments
Open

💡 per controller middlewares and exception handlers #6

lucas-labs opened this issue Nov 19, 2023 · 0 comments
Assignees
Labels
💡 feat New feature or request

Comments

@lucas-labs
Copy link
Owner

lucas-labs commented Nov 19, 2023

Some context...

  • FastAPI doesn't support this at all AFAIK.
  • starlette has an implementation for middlewares per group of routes on Mount:

https://github.com/encode/starlette/blob/93494a46ee0f2e8b1eeafd12e466ebac15037b41/starlette/routing.py#L380-L396

The problem with this is that if we use Mount instead of a subclass of APIRoute in FastAPI, we lose automatic openai schema definitions for those routes. They work just fine, we can access, routing works but FastAPI won't take them into account for its openai schema creation.

This is why:
https://github.com/tiangolo/fastapi/blob/ac93277d3b506f4076aee1af6ae5a86406f545c6/fastapi/openapi/utils.py#L481-L484

FastApi will ignore Mount objects inside its routes list.

Initial solution proposal

The only solution I can think of right now, would be to make our own implementation of Mount (e.g. PestMount), so that when we define a @controller, instead of creating an APIRouter for it and then add it to the FastAPI application, we create a PestMount grouping all the routes of the controller inside it.

Then we should mess a bit with the PestApplication class, overriding the openapi method from FastAPI so that it not only takes APIRoutes into account when generating the schema, but also all routes included on the PestMount route container.

@lucas-labs lucas-labs added the 💡 feat New feature or request label Nov 19, 2023
@lucas-labs lucas-labs self-assigned this Nov 19, 2023
@lucas-labs lucas-labs changed the title per controller middlewares and exception handlers 💡 per controller middlewares and exception handlers Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 feat New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant