Add regression test for Annotated ForwardRef OpenAPI (issue #13056)

This commit is contained in:
MuhammadUmar045 2026-02-21 10:31:13 +05:00
parent c44158384c
commit 6b16edfb5b
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
from typing import Annotated, Union
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
# This is the ForwardRef issue context
next_item: Annotated[Union["Item", None], None] = None
@app.get("/", response_model=Item)
def read_root():
return Item(name="root")
client = TestClient(app)
def test_issue_13056_openapi_annotated_forwardref():
# This triggers the schema generation where the crash usually happens
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
data = response.json()
assert data["components"]["schemas"]["Item"]