Browse Source

Merge 5a73b0bf09 into eb75fd078e

pull/14952/merge
Muhammad Umar Farooq 4 days ago
committed by GitHub
parent
commit
57a27c02c7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 29
      tests/test_issue_13056_openapi_annotated_forwardref.py

29
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"]
Loading…
Cancel
Save