I was using python 3.8 and an old version of FastAPI (0.75.0
) and when I did this
from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer
from typing_extensions import Annotated
app = FastAPI() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") @app.get("/items/")
async def read_items(
token: Annotated[str, Depends(oauth2_scheme)]
):
return {"token": token}
On swagger, the route said it had parameters, and any requests made without a body would fail with something like missing detail
.
The issue was the Annotated
. As soon as I removed this, the route didn’t expose the parameters from Depends()
:
@router.get("/me")
async def read_items(token: str = Depends(oauth2_scheme)):
return {"token": token}
Maybe support for Annotated
was added in a later version of FastAPI