Skip to content

Conversation

@joris-r
Copy link
Contributor

@joris-r joris-r commented Dec 29, 2025

See issue #30

I've checked the correct response type for SSE: it's "Content-Type: text/event-stream". Thus StreamingResponse



@app.get("/updates")
@app.get("/updates", response_class=StreamingResponse)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it just be DatastarResponse? What does that do to the swagger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With response_class=StreamingResponse,
swagger only says there is no parameters and code 200 as Successful Response.
There is no media type documented at all (but previously it incorrectly indicated an application/json, so it's better that way).

So in this way, it's consistent.

With response_class=DatastarResponse,
swagger crash with Fetch error : Internal Server Error /openapi.json
The exception stack trace says:

...
        external_docs=self.openapi_external_docs,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/joris/.cache/uv/environments-v2/app-df56c0d93ab9210a/lib/python3.13/site-packages/fastapi/openapi/utils.py", line 520, in get_openapi
    result = get_openapi_path(
        route=route,
    ...<3 lines>...
        separate_input_output_schemas=separate_input_output_schemas,
    )
  File "/home/joris/.cache/uv/environments-v2/app-df56c0d93ab9210a/lib/python3.13/site-packages/fastapi/openapi/utils.py", line 352, in get_openapi_path
    operation.setdefault("responses", {}).setdefault(status_code, {})[
                                                     ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'status_code' where it is not associated with a value

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks for testing. Let's put it how you have for now. I'm curious if we could fix DatastarResponse to be usable as a response_class (for both swagger and automatically transforming the returns) and what that would look like. For the swagger purposes I still don't think it's that important, because a d* app would tend to be a non-api app.

@gazpachoking gazpachoking merged commit 8053869 into starfederation:develop Dec 29, 2025
1 of 2 checks passed
@gazpachoking
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants