feat: add x-ogen-raw-response flag to yield full control#1522
Merged
ernado merged 3 commits intoogen-go:mainfrom Sep 18, 2025
Merged
feat: add x-ogen-raw-response flag to yield full control#1522ernado merged 3 commits intoogen-go:mainfrom
ernado merged 3 commits intoogen-go:mainfrom
Conversation
5118df0 to
f3e67c6
Compare
Member
|
Hi, thank you for your contribution. |
Member
|
Also, some opinionated SSE implementation can be added to ogen disregarding consensus in OpenAPI. |
f3e67c6 to
2e079f1
Compare
Contributor
Author
|
Great, thanks @ernado! I've rebased against main and resolved the conflict, but this has caused the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a workaround for #1375 that allows working with SSE streams outside of the generated client code.
I'm not sure if it'd be appropriate to add an SSE implementation at this time, since there currently isn't an agreed upon standard for how to interpret OpenAPI schemas for
text/event-streamresponses and there's lots of different ways people are constructing them. I did think of providing a basic wrapper around the exposedhttp.Responsethat implements the SSE protocol and could be updated later to handle decoding event data, but there's already established libraries out there that can do the job (albeit most of them do expect to own the request and response, not just the response, so not as straight forward as it could be).By adding
x-ogen-raw-response: trueto eachtext/event-streamresponse, this patch will cause ogen to expose the rawhttp.Responsewithout first reading it's body, e.g.:(this is just one example of how you might represent an SSE stream.)
This flag will also change server code-gen to give full control over the handler (I've separated these handlers into a new interface since the
Client's methods don't match the handler signatures for raw requests).One can also add an
application/jsonresponse with the same schema to generate encoders/decoders for it (I'd recommend doing this in a patch script, which I find myself reaching for with most OpenAPI schemas I encounter anyways).Now when we call our generated client method, we'll get something like this back:
Which we can then pass into our SSE reader of choice to stream the events.
This is most useful when also enabling request editing features:
We'd pass an option to either our client construction or the request method that sets the appropriate headers, e.g.: