[X] Make sure you are making a pull request against the main branch.
[X] Make sure your pull request title matches the requested format.
[X] Make sure to lint, type-check, and run unit and API tests.
Description
When sorted_routes=True, we have not been using "natural" sorting, but rather alphanuemeric sorting.
Example:
Routes:
GET /1
POST /1
GET /10
POST /10
GET /10/1
POST /2
These routes would be assigned the following string keys by `_get_unique_route_keys`:
/1|GET
/1|POST
/10|GET
/10|POST
/10/1|GET
/2|POST
We'd then use `sorted` on these keys, resulting in the following order:
/10/1|GET => GET /10/1
/10|GET => GET /10
/10|POST. => POST /10
/1|GET. => GET /1
/1|POST. => POST /1
/2|POST. => POST /2
This is not the behavior a human would typically expect.
Solution:
I'm using tuple keys in _get_unique_route_keys, so that route path lengths don't cause issues with the concatenated HTTP method.
I'm using the natsorted lib to naturally do the sorting instead of sorted. This will sort numbers in route paths (an atypical scenario) as expected.
New result:
('/1', 'GET') => GET /1
('/1', 'POST') => POST /1
('/2', 'POST') => POST /2
('/10', 'GET') => GET /10
('/10', 'POST') => POST /10
('/10/1', 'GET') => GET /10/1
If needed, a separate PR can address a new feature to allow for custom sorting of routes.
Pull Request Checklist
Description
When sorted_routes=True, we have not been using "natural" sorting, but rather alphanuemeric sorting. Example:
This is not the behavior a human would typically expect.
Solution:
_get_unique_route_keys
, so that route path lengths don't cause issues with the concatenated HTTP method.natsorted
lib to naturally do the sorting instead ofsorted
. This will sort numbers in route paths (an atypical scenario) as expected.New result:
If needed, a separate PR can address a new feature to allow for custom sorting of routes.