Browse Source
When an SSE route (or JSONL streaming route) is defined on an `APIRouter` and merged onto a `FastAPI` app via `include_router`, the merged route silently lost its `stream_item_type`. As a consequence the emitted OpenAPI schema dropped the `contentSchema` describing the streamed item and downstream tools (`datamodel-codegen`, etc.) could no longer generate frame models from the spec. Root cause: `APIRoute.__init__` only ran stream-item detection inside the `isinstance(response_model, DefaultPlaceholder)` branch. The source route's `__init__` collapses `self.response_model` to `None` after detection, so when `APIRouter.include_router` re-instantiates the route via `add_api_route(response_model=route.response_model, ...)` the new init sees an explicit `None` and skips detection entirely. Fix: also run detection when `response_model is None` on entry, and restrict the "promote return annotation to response_model" fallback to the original `DefaultPlaceholder` case so an explicit `response_model= None` still disables response validation as documented. Adds a regression test asserting both `stream_item_type` propagation and the presence of `contentSchema` in the merged route's OpenAPI. Co-Authored-By: Claude Code <[email protected]>pull/15497/head
2 changed files with 74 additions and 2 deletions
Loading…
Reference in new issue