From 9f917e488780db3d42a1fa04502a3ac259233499 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Wed, 11 Mar 2026 09:16:56 +0100 Subject: [PATCH] Fix response_model being set to None for non-generator endpoints --- fastapi/routing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index c7973aa22..9823fe198 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -932,10 +932,11 @@ class APIRoute(routing.Route): response_model = None else: stream_item = get_stream_item_type(return_annotation) - if stream_item is not None: - # Extract item type for JSONL or SSE streaming when - # response_class is DefaultPlaceholder (JSONL) or - # EventSourceResponse (SSE). + if stream_item is not None and is_generator: + # Extract item type for JSONL or SSE streaming for + # generator endpoints when response_class is + # DefaultPlaceholder (JSONL) or EventSourceResponse + # (SSE). # ServerSentEvent is excluded: it's a transport # wrapper, not a data model, so it shouldn't feed # into validation or OpenAPI schema generation.