alexschimpf / fastapi-versionizer

FastAPI Versionizer
MIT License
79 stars 13 forks source link

Now using natural sorting for routes for sorted_routes=True #29

Closed alexschimpf closed 11 months ago

alexschimpf commented 11 months ago

Pull Request Checklist

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:

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.

alexschimpf commented 11 months ago

:tada: This PR is included in version 1.1.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: