quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Smallrye OpenAPI generation for SSE with Multi return type generates array type

Open andreas-repp opened this issue 1 month ago • 7 comments

Describe the bug

When generating the OpenAPI for a REST endpoint producing SSE that returns a Multi, the generated type is wrong.

Code:

    @GET
    @Path("/multi")
    @Produces(MediaType.SERVER_SENT_EVENTS)
    fun helloMulti(): Multi<String> = Multi.createFrom().items("1", "2", "3")

This generates the following OpenAPI Spec

openapi: 3.1.0
paths:
  /hello/multi:
    get:
      responses:
        "200":
          description: OK
          content:
            text/event-stream:
              schema:
                type: array
                items:
                  type: string
      summary: Hello Multi
      tags:
      - Greeting Resource

Here, the schema of the text/event-stream is of type array with items of type string. However, we do not return arrays of strings but only strings in a stream.

If we generate the same OpenAPI Spec with the method returning a Kotlin Flow, the generated result is correct.

openapi: 3.1.0
paths:
  /hello/flow:
    get:
      responses:
        "200":
          description: OK
          content:
            text/event-stream:
              schema:
                type: string
      summary: Hello Flow
      tags:
      - Greeting Resource

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

Reproducer: 2025-11-19_Multi-OpenAPI-Bug.zip

  1. Unzip the reproducer
  2. run ./gradlew assemble
  3. Check out the OpenAPI Spec in the openapi directory.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

Quarkus 3.29.3

Build tool (ie. output of mvnw --version or gradlew --version)

gradlew

Additional information

No response

andreas-repp avatar Nov 19 '25 10:11 andreas-repp

/cc @EricWittmann (openapi), @Ladicek (smallrye), @MikeEdgar (openapi), @geoand (kotlin), @jmartisk (smallrye), @phillip-kruger (openapi,smallrye), @radcortez (smallrye)

quarkus-bot[bot] avatar Nov 19 '25 10:11 quarkus-bot[bot]

@andreas-eberle have you tried using an annotation on the REST method to provide the schema you're looking for? Something like this:

@APIResponseSchema(String.class)

MikeEdgar avatar Nov 20 '25 17:11 MikeEdgar

Hi @MikeEdgar,

yes, using the annotation fixes it. But shouldn't Quarkus detect it correctly automatically? Like it does with the Flow.

andreas-repp avatar Nov 26 '25 16:11 andreas-repp

That is probably reasonable, but I wonder does it universally apply for any Multi<T> with a content-type of text/event-stream ?

MikeEdgar avatar Dec 01 '25 19:12 MikeEdgar

I'm not sure what exactly you mean. Can you explain a bit more? Then I could test it.

andreas-repp avatar Dec 01 '25 20:12 andreas-repp

@andreas-eberle I just am questioning whether a Multi always (or more often than not) should result in the response schema you're expecting rather than an array. I'm unsure myself.

MikeEdgar avatar Dec 04 '25 11:12 MikeEdgar

I think at least in the case of an SSE response format, It should not be an array. If it makes sense to use Multi for non-SSE, I don't know.

andreas-repp avatar Dec 04 '25 12:12 andreas-repp