You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[REQ] [rust-axum] support text/event-stream #21967
Is your feature request related to a problem? Please describe.
Currently, the rust-axum server generator only supports application/json responses. This feature request is for the generator to also support endpoints that respond with a stream or MAY respond with a stream.
Describe the solution you'd like
Ideally, the solution is for the traits created for a route to take into account a return value enum that is either a singular value or is a Box<dyn futures::Stream<Item=T> + Send + 'static> (and potentially Unpin?). Then in the route implementation, I can decide if I stream or not and return the appropriate enum variant.
Describe alternatives you've considered
Do it myself by modifying the generated source code in my project - not currently aware of any other options available within this tool.
Additional context
Filing a new ticket for this after quickly discussing with @linxGnu on another ticket. I am interested in contributing on something like this in order to speed up the process, if possible - but I would definitely need guidance and a little hand-holding. This feels like a larger feature than a regular old “first issue”.
Hi @linxGnu - like I mentioned, definitely interested. I guess I would need to be pointed pretty explicitly at
Samples of this behavior in another language in the language processor
Samples of this behavior in another mustache template
I think there’s also some design to discuss - namely, I can describe how I edited the generated code in order to enable streaming myself.
The key I found was I needed a way to sometimes return a result matching the type signature in https://docs.rs/axum/latest/axum/body/struct.Body.html#method.from_stream. This created a good amount of issues around how to box the item appropriately in an Enum variant for the return type so that the actual route could match on it.
What I ended up doing was using Axum’s IntoResponse trait as the return type (impl IntoResponse) and pulling some of the generated code down into my api trait implementation. This let me decide if I wanted to stream or not and simply return and object that could be turned into a response (in particular, a body of whichever kind I wanted).
I don’t believe my implementation is “correct” - it changes the return type and isolation of the trait too much. Maybe I could get your thoughts on the right way to go - simply boxing the stream in an enum variant? Or another direction entirely?
Good, I like that proposal. One thing I would add is that instead of forcing the user to yield Event as apart of the item, we should implement Into on any type that will be streamed.
Still leaves a few questions on boxing the SSE<…> but I think we’ll have to figure those out as we go.
Hi @linxGnu - I spent the day trying to research the best way to go about this and came up empty handed. I don’t know enough about the codebase to implement this feature without some very direct guidance on what to add & change.
I wonder if we have any guideline/book about OpenAPI Generator Engine, specially flow & hooks (pre-processors, post-processors). I think it will help @jacob-vincent-mink a lot to understand the codebase, not only Rust Axum but other generators
Perhaps I was a little dramatic yesterday :)
I worked with a friend to understand the code a little deeper and figured out I needed to modify the fromOperations method and some other related spots. Please see the PR linked that implements this feature for stream and multi-part content.
Activity
linxGnu commentedon Oct 7, 2025
@jacob-vincent-mink
As recent release for anyOf, oneOf; I think it's time for this feature. Please let me know if you can make PR
jacob-vincent-mink commentedon Oct 7, 2025
Hi @linxGnu - like I mentioned, definitely interested. I guess I would need to be pointed pretty explicitly at
I think there’s also some design to discuss - namely, I can describe how I edited the generated code in order to enable streaming myself.
The key I found was I needed a way to sometimes return a result matching the type signature in https://docs.rs/axum/latest/axum/body/struct.Body.html#method.from_stream. This created a good amount of issues around how to box the item appropriately in an Enum variant for the return type so that the actual route could match on it.
What I ended up doing was using Axum’s IntoResponse trait as the return type (impl IntoResponse) and pulling some of the generated code down into my api trait implementation. This let me decide if I wanted to stream or not and simply return and object that could be turned into a response (in particular, a body of whichever kind I wanted).
I don’t believe my implementation is “correct” - it changes the return type and isolation of the trait too much. Maybe I could get your thoughts on the right way to go - simply boxing the stream in an enum variant? Or another direction entirely?
linxGnu commentedon Oct 7, 2025
@jacob-vincent-mink
I think we should directly utilize: https://docs.rs/axum/0.8.6/axum/response/sse/index.html
Thus, returning
Sse<impl Stream<Item = Result<Event, Infallible>>>from request handler. a.k.a, force user to return itlinxGnu commentedon Oct 7, 2025
From user perspective:
jacob-vincent-mink commentedon Oct 7, 2025
Good, I like that proposal. One thing I would add is that instead of forcing the user to yield Event as apart of the item, we should implement Into on any type that will be streamed.
Still leaves a few questions on boxing the SSE<…> but I think we’ll have to figure those out as we go.
linxGnu commentedon Oct 8, 2025
@jacob-vincent-mink Yes, anything that could "Into" TryStream
Please go ahead with your implementation
jacob-vincent-mink commentedon Oct 8, 2025
Hi @linxGnu - I spent the day trying to research the best way to go about this and came up empty handed. I don’t know enough about the codebase to implement this feature without some very direct guidance on what to add & change.
linxGnu commentedon Oct 8, 2025
Hi @wing328
I wonder if we have any guideline/book about OpenAPI Generator Engine, specially flow & hooks (pre-processors, post-processors). I think it will help @jacob-vincent-mink a lot to understand the codebase, not only Rust Axum but other generators
jacob-mink-1996 commentedon Oct 9, 2025
Perhaps I was a little dramatic yesterday :)
I worked with a friend to understand the code a little deeper and figured out I needed to modify the
fromOperationsmethod and some other related spots. Please see the PR linked that implements this feature for stream and multi-part content.