- 
                Notifications
    You must be signed in to change notification settings 
- Fork 43
Description
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.
- Request comes
- pick version (version picking middleware)
- migration middleware
- Get body for old version
- solve_dependencies for old version
- convert to latest
- set api version header to latest version
 
- run the endpoint
However, there is a small difficulty with this: we will need to match request before starlette does. I.e. We will be doing double work with starlette which can be quite unwanted. If we want to follow this route, we can use route.matches and only migrate if the we found a FULL match because PARTIAL matches are only there for 405 Method not allowed errors.