From 56af14bb88bc3b4caa954cf27eb45b307fbba1ba Mon Sep 17 00:00:00 2001 From: Alexander Rauhut Date: Sun, 8 Mar 2026 18:07:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20stream=20schema=20lost=20w?= =?UTF-8?q?hen=20using=20include=5Frouter()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Propagate stream_item_type through add_api_route so that include_router preserves the already-computed stream item type for SSE and JSONL endpoints. --- tests/test_sse.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_sse.py b/tests/test_sse.py index b58e547353..8ca90fe720 100644 --- a/tests/test_sse.py +++ b/tests/test_sse.py @@ -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")