koxudaxi / fastapi-code-generator

This code generator creates FastAPI app from an openapi file.
MIT License
1.08k stars 109 forks source link

Inconsistance of code when doing sorting of routes and tags #416

Open azdolinski opened 6 months ago

azdolinski commented 6 months ago

In case when you have all router with lowercase letters.... and we add some router called "urlscraper", + uppercase tag like "URLScraper", this will cause inconsistrance between routers and tags arrays which cause mismatch between route and file name (generated based on tags names). Python sorted tags in lexicographical (alphabetical) order, 'U', will comes before the lowercase letters and become on first element in the array. In case of routes you using lower() function for tags and that cause inconsistence.

    routers = sorted(
        [re.sub(TITLE_PATTERN, '_', tag.strip()).lower() for tag in sorted_tags]
    )

fix:

    sorted_tags = sorted(set(all_tags), key=lambda x: x.lower())

then both arrays (routers and _sortedtags) will be sorted in sam way.