mirror of https://github.com/tiangolo/fastapi.git
🐛 Fix stream schema lost when using include_router()
Propagate stream_item_type through add_api_route so that include_router preserves the already-computed stream item type for SSE and JSONL endpoints.
This commit is contained in:
parent
b54f6dea01
commit
56af14bb88
|
|
@ -277,6 +277,24 @@ def test_sse_on_router_included_in_app(client: TestClient):
|
|||
assert len(data_lines) == 2
|
||||
|
||||
|
||||
def test_sse_router_typed_stream(client: TestClient):
|
||||
response = client.get("/api/events-typed")
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"] == "text/event-stream; charset=utf-8"
|
||||
data_lines = [
|
||||
line for line in response.text.strip().split("\n") if line.startswith("data: ")
|
||||
]
|
||||
assert len(data_lines) == 3
|
||||
|
||||
|
||||
def test_jsonl_router_typed_stream(client: TestClient):
|
||||
response = client.get("/api/events-jsonl")
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"] == "application/jsonl"
|
||||
lines = response.text.strip().split("\n")
|
||||
assert len(lines) == 3
|
||||
|
||||
|
||||
def test_sse_router_typed_openapi_schema(client: TestClient):
|
||||
"""Typed SSE endpoint on a router should preserve itemSchema with contentSchema."""
|
||||
response = client.get("/openapi.json")
|
||||
|
|
|
|||
Loading…
Reference in New Issue