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

Convert Cadwyn to a middleware #214

Open
zmievsa opened this issue Sep 21, 2024 · 1 comment
Open

Convert Cadwyn to a middleware #214

zmievsa opened this issue Sep 21, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@zmievsa
Copy link
Owner

zmievsa commented Sep 21, 2024

Currently, FastAPI first validates a request in its correct version, and then we migrate request to latest. For responses, it goes in reverse: we migrate response from latest, and then FastAPI validates the response. This approach tightly binds our versioning logic to FastAPI and causes us to do a lot of hacks. Instead, we should use a middleware that will see each request first and convert it to latest. This will significantly simplify our code and make it easier for us to keep compatibility with future FastAPI versions.

  1. Request comes
  2. pick version (version picking middleware)
  3. migration middleware
    1. Get body for old version
    2. solve_dependencies for old version
    3. convert to latest
    4. set api version header to latest version
  4. run the endpoint
@zmievsa zmievsa added the enhancement New feature or request label Sep 21, 2024
@zmievsa zmievsa self-assigned this Sep 21, 2024
@zmievsa
Copy link
Owner Author

zmievsa commented Oct 6, 2024

Alternatively, custom route classes might be a good fit.
https://fastapi.tiangolo.com/how-to/custom-request-and-route/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant