pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
533 B
23 lines
533 B
from typing import Annotated, ForwardRef
|
|
|
|
from fastapi import Depends, FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_annotated_forwardref_dependency():
|
|
app = FastAPI()
|
|
|
|
User = ForwardRef("User")
|
|
|
|
def get_user() -> "User":
|
|
return {"name": "amulya"}
|
|
|
|
@app.get("/")
|
|
def read_user(user: Annotated[User, Depends(get_user)]):
|
|
return user
|
|
|
|
client = TestClient(app)
|
|
response = client.get("/")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json() == {"name": "amulya"}
|
|
|