[REQ] (Java,...) Support Server Sent Events
Is your feature request related to a problem? Please describe.
It is currently impossible to generate stubs and support server sent events in some languages (like Java JAX-RS spec) since there is missing code for SSE (text/event-stream).
Describe the solution you'd like
Introduce isEventStream property in Operation class (and set to true if produces has text/event-stream value) and add missing information to templates (@Context SseEventSink for Java) etc...
Describe alternatives you've considered
/
Additional context
/
Any news?
Hello there :wave:
I require this feature too, and I am willing to contribute a Pull Request. First of all, I'd like to make sure that the PR gets eventually merged in the end, so some feedback from a maintainer (@cachescrubber ?) would be awesome.
- Is it okay to implement
SseEmitteronly for the Spring generator or is it required to provide similar implementations for all available code generators? - From my understanding
apiController.mustacheneeds to be adjusted to conditionally returnSseEmitterinstead ofResponseEntity - The return value of the generated method should be
SseEmitterinstead ofResponseEntityin case- the
contentproperty has settext-eventstreamas type and - the
typeisarrayand - the
formatisevent-stream?
- the
/notifications:
get:
description: Retrieve notifications
operationId: getNotifications
responses:
200:
description: Currently active operation
content:
text/event-stream:
schema:
type: array
format: event-stream
items:
$ref: '#/components/schemas/Notification'
- Further
SpringCodegen.javawould need to be adjusted to fill in the neededimportstatements and set thebooleanswitch to make the decision in the template which response type to use - Which further stuff did I possibly miss?
Any advances or alternatives? I would need this feature too.
+1!
Hi y'all, I'm trying to consume from a server sent event stream using a java sdk generated by the openapi-generator, and I'm having trouble with this..
Using a generated python sdk, I was able to use preload_content = False so that I could process the events while the connection is open, but in the java sdk generated, I haven't determined a way to do that.
@danipenaperez, @stefan-niedermann, @jorgerod, @gpor0, Any luck on this, or do you have any tips? I might fork and try to add it myself if it is not possible as is.
I did not make any progress and I see this topic totally blocked.
Recent AI era requires SSE than before. I hope SSE is supported.
@ https://github.com/OpenAPITools/openapi-generator/issues/6123#issuecomment-1050889080:
The return value of the generated method should be
SseEmitterinstead ofResponseEntityin case
- the
contentproperty has settext-eventstreamas type and- the
typeisarrayand- the
formatisevent-stream?/notifications: get: description: Retrieve notifications operationId: getNotifications responses: 200: description: Currently active operation content: text/event-stream: schema: type: array format: event-stream items: $ref: '#/components/schemas/Notification'
This is exactly the style we would like to use in. We are running a Spring application, so having it purely for a SpringCodegen would work fine for us.
Another contribution which referencing this one has already added support for reactive Spring applications, but we have an application which is mostly non-reactive (with ResponseEntities), and only has a couple of server-sent event endpoints we implement with SseEmitters.
Am I correct in understanding that as of now Openapi-generator only supports SSE for Spring?
Yes, the https://github.com/OpenAPITools/openapi-generator/pull/16543 introduced it for spring
Does it have something similar for Python?
Yes, the #16543 introduced it for spring
Are there plans to introduce it also for the java generator? I need to generate a client to call a Python service (that returns SSE) from my Spring application