OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.89k stars 6.58k forks source link

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

Open gpor0 opened 4 years ago

gpor0 commented 4 years ago

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

/

jorgerod commented 3 years ago

Any news?

stefan-niedermann commented 2 years ago

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'
  4. 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
  5. Which further stuff did I possibly miss?
danipenaperez commented 2 years ago

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

danipenaperez commented 2 years ago

+1!

reidmeyer commented 2 years ago

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.

jorgerod commented 2 years ago

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

SokichiFujita commented 1 year ago

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

lesteenman commented 5 months ago

@ 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.

benjjs commented 1 week ago

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

krasv commented 1 week ago

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