First Check
Commit to Help
Example Code
# main.py
from fastapi import FastAPI, APIRouter
from .child import child_router
app = FastAPI()
router = APIRouter()
router.include_router(child_router, prefix='/foo')
app.include_router(router, prefix='/api/v1', include_in_schema=True)
# .child/__init__.py
from fastapi import APIRouter
from .grandchild import grandchild_router
child_router = APIRouter()
child_router.include_router(grandchild_router)
# ..grandchild/__init__.py
from fastapi import APIRouter
grandchild_router = APIRouter()
@grandchild_router.get('')
def test():
return 'bar'
Description
I currently have something similar setup as the example code. main_router > child_router > grandchild_router. I am setting a prefix on the child router level (during the include_router call). When I set the prefix on the child level, I cannot use an empty path on the grandchild level router.
If I do, I got the following error:
Exception: Prefix and path cannot be both empty (path operation: test)
My file structure looks like this.
project
│ main.py (main_router)
└───child
│ │ __init__.py (child_router)
│ └───grandchild
│ │ __init__.py (grandchild_router)
### Operating System
macOS
### Operating System Details
_No response_
### FastAPI Version
0.75.0
### Python Version
Python 3.9.10
### Additional Context
_No response_
First Check
Commit to Help
Example Code
Description
I currently have something similar setup as the example code. main_router > child_router > grandchild_router. I am setting a prefix on the child router level (during the include_router call). When I set the prefix on the child level, I cannot use an empty path on the grandchild level router.
If I do, I got the following error:
Exception: Prefix and path cannot be both empty (path operation: test)My file structure looks like this.