Skip to content

APIRouter: unexpected keyword argument 'prefix' #2726

@jintolonappan

Description

@jintolonappan

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Issue

I was following the official tutorial related to bigger applications and came across a TypeError with all the parameters to APIRouter()

Examples:

TypeError: __init__() got an unexpected keyword argument 'prefix'
TypeError: __init__() got an unexpected keyword argument 'tags'
TypeError: __init__() got an unexpected keyword argument 'responses'

Code used:

router = APIRouter(
    prefix="/items",
    tags=["items"],
    dependencies=[Depends(get_token_header)],
    responses={404: {"description": "Not found"}},
)

However, I noticed that each of the argument works if I use them in main.py as:

app.include_router(
    admin.router,
    prefix="/admin",
    tags=["admin"],
    dependencies=[Depends(get_token_header)],
    responses={418: {"description": "I'm a teapot"}},
)

Is this an issue in documentation or code?

Environment

  • OS: macOS Catalina 10.15.7
  • FastAPI Version: 0.61.1
  • Python version: Python 3.8.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions