From 6b16edfb5bc445ea28fde5e154b2c120315af1f0 Mon Sep 17 00:00:00 2001 From: MuhammadUmar045 Date: Sat, 21 Feb 2026 10:31:13 +0500 Subject: [PATCH 1/2] Add regression test for Annotated ForwardRef OpenAPI (issue #13056) --- ...ssue_13056_openapi_annotated_forwardref.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_issue_13056_openapi_annotated_forwardref.py diff --git a/tests/test_issue_13056_openapi_annotated_forwardref.py b/tests/test_issue_13056_openapi_annotated_forwardref.py new file mode 100644 index 0000000000..653e31d8d9 --- /dev/null +++ b/tests/test_issue_13056_openapi_annotated_forwardref.py @@ -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"] \ No newline at end of file From 5a73b0bf096dc9bb6acc0eca69a8f54624b19b2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Sat, 21 Feb 2026 05:34:18 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_issue_13056_openapi_annotated_forwardref.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_issue_13056_openapi_annotated_forwardref.py b/tests/test_issue_13056_openapi_annotated_forwardref.py index 653e31d8d9..173919123c 100644 --- a/tests/test_issue_13056_openapi_annotated_forwardref.py +++ b/tests/test_issue_13056_openapi_annotated_forwardref.py @@ -26,4 +26,4 @@ def test_issue_13056_openapi_annotated_forwardref(): response = client.get("/openapi.json") assert response.status_code == 200, response.text data = response.json() - assert data["components"]["schemas"]["Item"] \ No newline at end of file + assert data["components"]["schemas"]["Item"]