connexion icon indicating copy to clipboard operation
connexion copied to clipboard

Sort routes in RoutingMiddleware

Open kosciCZ opened this issue 11 months ago • 6 comments

Fixes #1879

Please let me know if this is the correct place to perform the sort or if any more changes are needed.

I've ran into this issue while migrating a large API from connexion 2 to connexion 3 (Async app variant) and the changes implemented here fixed route mismatching.

kosciCZ avatar Mar 18 '24 14:03 kosciCZ

Thanks @kosciCZ, I think we need to update this in the AbstractRoutingMiddleware though.

RobbeSneyders avatar Mar 20 '24 20:03 RobbeSneyders

Hi @kosciCZ, do you have time to have another look at this?

RobbeSneyders avatar Apr 15 '24 19:04 RobbeSneyders

@RobbeSneyders sorry about that, yes, definitely. Could you throw me some pointers on the general outline of the solution?

My idea with this was that this is mostly Starlette specific, since their route matching iterates over routes and performs regex matches until a match is found, so order is important. With Flask, this does not seem to be an issue (our API on sync connexion 2.x matched routes correctly without having to sort them). So, that's why I chose to sort them all after the routes have been mounted, as that seemed like the appropriate place. Would you like me to replicate that in the method you referenced?

kosciCZ avatar Apr 15 '24 19:04 kosciCZ

@RobbeSneyders any thoughts on ^?

kosciCZ avatar May 06 '24 13:05 kosciCZ

Hi @kosciCZ, I would prefer to update it in the AbstractRoutingMiddleware, so the behavior is consistent across all places where we are routing requests, even if the resulting behavior is the same.

RobbeSneyders avatar May 27 '24 09:05 RobbeSneyders

Coverage Status

coverage: 94.2% (+0.003%) from 94.197% when pulling 93c4a1e6ab1df76ea0cea8bdb264bdd0d8562f68 on kosciCZ:sort-routes-middleware into 160a1c0e710d04d3c452a45113d7c29d7e528215 on spec-first:main.

coveralls avatar May 27 '24 09:05 coveralls