Skip to content
Discussion options

You must be logged in to vote

I hit the same thing and I believe the root cause is include_router(). Same endpoint, different schema depending on how it's registered:

from collections.abc import AsyncIterable

from fastapi import APIRouter, FastAPI
from fastapi.sse import EventSourceResponse
from pydantic import BaseModel


class ExampleEvent(BaseModel):
    message: str
    id: int

app = FastAPI()
sse_router = APIRouter()

@app.post("/direct", response_class=EventSourceResponse)
async def direct() -> AsyncIterable[ExampleEvent]:
    for i in range(10):
        yield ExampleEvent(message=f"Hello {i}", id=i)

@sse_router.post("/routed", response_class=EventSourceResponse)
async def routed() -> AsyncIterable[ExampleEvent

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tiangolo
Comment options

Answer selected by tiangolo

This comment was marked as spam.

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
5 participants