Skip to content

Conversation

@Theo-Steiner
Copy link

@Theo-Steiner Theo-Steiner commented Nov 20, 2025

Closes #2641

Background

The individual results yielded by the async iterator for the SSE client are just the data part of the server sent events.
The type however, suggests that it should be the full event.

Description

This PR changes the returned value to be the full event, including id, event, data & retry.
Since retry is not part of the actual event, it is not included.

Notes

The SDK snapshot tests started failing because they expected the previous function implementation.
Should I update them manually to reflect the new function body or is there a way to regenerate them automatically?

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

🦋 Changeset detected

Latest commit: c3aba80

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 20, 2025

@Theo-Steiner is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug 🔥 Something isn't working client Client package related labels Nov 20, 2025
@mrlubos
Copy link
Member

mrlubos commented Nov 20, 2025

@Theo-Steiner run pnpm test:update to update snapshots. However, I'm confused by this issue because server-sent events are working in the Opencode example https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts#L24. I worry making this change would break that functionality. To me it sounds like there's something else going on

@Theo-Steiner
Copy link
Author

Theo-Steiner commented Nov 21, 2025

@mrlubos thank you for your quick reply!
The opencode example you linked seems to only check whether you can connect to a server sent event source. This works without problems already.
The issue is that the stream property returned by sse.get() contains only the data, whereas the types say it would contain the entire event.

// ASIS
export const { stream } = getSse();

for await (const result of stream) {
  // `result` is typed as `GetSseResponses`, but the actual result is `GetSseResponses['data']`
  console.log(result.event) // event will always be undefined, since we are passed only the data
}

// TOBE
for await (const result of stream) {
  // `result` is still typed as `GetSseResponses`, however the actual result is now the complete event (not just it's data property)
  console.log(result.event) // logs the actual event
}

As you can see, there is currently a bug in the SSE implementation, where the result.data property is returned when the types promise the entire result object should be returned instead.
As far as I can see it, there's two ways to fix it:

  1. adjust the yielded value to match the types (this PR)
  2. change the types to match the yielded value (this would make the stream property of the sse results basically useless, since the data is not really useful without the event type)

@Theo-Steiner
Copy link
Author

Theo-Steiner commented Nov 21, 2025

I've updated the tests, which sadly bloats the diff of this PR by quite a bit 😅
also looks like pnpm examples:generate doesn't update the examples anymore..?

@jscarle
Copy link

jscarle commented Nov 22, 2025

❤️ I'm so looking forward to this. Thanks!

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

Labels

bug 🔥 Something isn't working client Client package related size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncGenerator of a text/event-stream returns the data only

3 participants