openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ] (Java,...) Support Server Sent Events

Open gpor0 opened this issue 5 years ago • 11 comments

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

/

gpor0 avatar Apr 30 '20 21:04 gpor0

Any news?

jorgerod avatar Dec 09 '20 13:12 jorgerod

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.

  1. Is it okay to implement SseEmitter only for the Spring generator or is it required to provide similar implementations for all available code generators?
  2. From my understanding apiController.mustache needs to be adjusted to conditionally return SseEmitter instead of ResponseEntity
  3. The return value of the generated method should be SseEmitter instead of ResponseEntity in case
    • the content property has set text-eventstream as type and
    • the type is array and
    • the format is event-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'
  1. Further SpringCodegen.java would need to be adjusted to fill in the needed import statements and set the boolean switch to make the decision in the template which response type to use
  2. Which further stuff did I possibly miss?

stefan-niedermann avatar Feb 25 '22 14:02 stefan-niedermann

Any advances or alternatives? I would need this feature too.

danipenaperez avatar Sep 22 '22 07:09 danipenaperez

+1!

danipenaperez avatar Sep 22 '22 07:09 danipenaperez

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.

reidmeyer avatar Oct 24 '22 13:10 reidmeyer

I did not make any progress and I see this topic totally blocked.

jorgerod avatar Nov 10 '22 09:11 jorgerod

Recent AI era requires SSE than before. I hope SSE is supported.

SokichiFujita avatar Aug 17 '23 09:08 SokichiFujita

@ https://github.com/OpenAPITools/openapi-generator/issues/6123#issuecomment-1050889080:

The return value of the generated method should be SseEmitter instead of ResponseEntity in case

  • the content property has set text-eventstream as type and
  • the type is array and
  • the format is event-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.

lesteenman avatar Jun 06 '24 09:06 lesteenman

Am I correct in understanding that as of now Openapi-generator only supports SSE for Spring?

benjjs avatar Nov 05 '24 19:11 benjjs

Yes, the https://github.com/OpenAPITools/openapi-generator/pull/16543 introduced it for spring

krasv avatar Nov 08 '24 15:11 krasv

Does it have something similar for Python?

vidolch avatar Jun 03 '25 11:06 vidolch

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