Describe the bug
When I use CBV with a router that has a prefix, the prefix is included twice.
fromfastapiimportAPIRouterfromfastapi_utils.cbvimportcbvrouter=APIRouter(prefix='/api/v1')
@cbv(router)classC:
@router.get('')deff(self):
...
assertrouter.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 calls router.add_api_route which adds a prefix to the path.cbv calls router.include_router(cbv_router) which again calls router.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
forrouteincbv_routes:
router.routes.remove(route)
_update_cbv_route_endpoint_signature(cls, route)
cbv_router.routes.append(route)
router.include_router(cbv_router)
do
forrouteincbv_routes:
_update_cbv_route_endpoint_signature(cls, route)
Describe the bug
When I use CBV with a router that has a prefix, the prefix is included twice.
This is because the path already has a prefix before CBV removes and re-adds it to a router:
@router.getcallsrouter.add_api_routewhich adds a prefix to the path.cbvcallsrouter.include_router(cbv_router)which again callsrouter.add_api_routewhich 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
do