-
Notifications
You must be signed in to change notification settings - Fork 176
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When I use CBV with a router that has a prefix, the prefix is included twice.
from fastapi import APIRouter
from fastapi_utils.cbv import cbv
router = APIRouter(prefix='/api/v1')
@cbv(router)
class C:
@router.get('')
def f(self):
...
assert router.routes[-1].path == '/api/v1/api/v1'
>>> print(fastapi_utils.__version__)
0.2.1
>>> print(fastapi.__version__)
0.63.0
This is because the path already has a prefix before CBV removes and re-adds it to a router:
@router.get
callsrouter.add_api_route
which adds a prefix to the path.cbv
callsrouter.include_router(cbv_router)
which again callsrouter.add_api_route
which adds a prefix to the path.
One solution would be to not remove and re-add routes here, and only change the signature, so instead of
for route in cbv_routes:
router.routes.remove(route)
_update_cbv_route_endpoint_signature(cls, route)
cbv_router.routes.append(route)
router.include_router(cbv_router)
do
for route in cbv_routes:
_update_cbv_route_endpoint_signature(cls, route)
eduardostarling, negadive, pavlok311, falkben, phillipuniverse and 13 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working