awtkns / fastapi-crudrouter

A dynamic FastAPI router that automatically creates CRUD routes for your models
https://fastapi-crudrouter.awtkns.com
MIT License
1.37k stars 154 forks source link

Model preffix is not lowercased in TortoiseCRUDRouter #64

Closed marcoaaguiar closed 3 years ago

marcoaaguiar commented 3 years ago

When using TortoiseCRUDRouter, the CRUD routers generate a base prefix that has the same casing as the db_model.

For instance, for a router with prefix "/api", and an object CRUD router defined by

router.include_router(TortoiseCRUDRouter(schema=UserPydantic, db_model=User))

The generated CRUD route that appears in the /doc is /api/User, which is quite odd for APIs.

This issue seems to come from the interaction of these 2 lines https://github.com/awtkns/fastapi-crudrouter/blob/e1a4a2b6e363ad82c3a2b0058e7029824eae5771/fastapi_crudrouter/core/tortoise.py#L48 and https://github.com/awtkns/fastapi-crudrouter/blob/e1a4a2b6e363ad82c3a2b0058e7029824eae5771/fastapi_crudrouter/core/_base.py#L49

Since the prefix is defined in the TortoiseCRUDRouter, it is never lowercased

This might be intended. Anyway, this behavior can be circumvented by passing prefix to the TortoiseCRUDRouter.

awtkns commented 3 years ago

Hi @marcoaaguiar thanks for reporting this.

In #65 I've changed it so that all prefixes are lowercase. Even if you specifyprefix="MyModel" it would turn into "mymodel". That being said, this could cause problems if someone wanted an uppercase path prefix (for whatever reason). Alternatively, I can just fix the tortoise issue,

Thoughts?

marcoaaguiar commented 3 years ago

Hi Adam, I believe that would fix the issue.

I started using this package this morning, and it's great to see that it is under development/maintenance! The only feature that seems to be missing is filtering, but it seems that soon it will be available (#61).

When #65 is merged, feel free to close this issue.

awtkns commented 3 years ago

Awesome! Thanks for the feedback, filtering will be released soon 😃