Skip to content

[BUG] Path parameter type changes to query in openapi docs for nested routers #1454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kanishk619 opened this issue Apr 27, 2025 · 3 comments

Comments

@kanishk619
Copy link

Describe the bug
When using nested routers, the path parameter of the parent router gets changed to query in openapi docs. I encountered this error while using orval for generating client

  • Python version: 3.13
  • Django version: 5.2
  • Django-Ninja version: 1.4.1
  • Pydantic version: 2.11.3
# api.py

from ninja import NinjaAPI
from ninja.security import django_auth

from app.api.tasks import tasks_router
from app.api.project import project_router


api = NinjaAPI(auth=django_auth)
api.add_router("/projects", project_router)
project_router.add_router("/{project_id}/tasks/", tasks_router)
# task.py

from ninja import Router

task_router = Router(tags=["tasks"])


@task_router.get("/")
def list_tasks(request, project_id: int):
    return []

Image

The parameter has to be set explicitly to Path in the child router routes as below in order to set the parameter as path parameter

# task.py

from ninja import Router, Path

task_router = Router(tags=["tasks"])


@task_router.get("/", operation_id="list_project_tasks")
def list_tasks(request, project_id: int = Path(...)):
    return []

Image

@kanishk619
Copy link
Author

Looks like this is duplicate of #1055

@vitalik
Copy link
Owner

vitalik commented Apr 27, 2025

well, this might be not fixable...

the idea is that you can create one router and attach it to multiple paths (one can include {path-param} other not

I'm pro explicit marking it as project_id: Path[int] so that it clearly visible in code context

On the other hand might be practical to throw some warning is param_name is clashes with path {param}

@kanishk619
Copy link
Author

That makes sense. Good to have this updated in documentation somewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants