Skip to content

Flow<T> should be detected as an array schema for non-SSE endpoints #2535

@daniel-leib-fnt

Description

@daniel-leib-fnt

kotlinx.coroutines.flow.Flow is currently registered as a wrapper type (similar to Uni and CompletableFuture) in TypeUtil, which causes it to be unwrapped to its type parameter T and emitted as a single-element schema. This is correct behavior when the endpoint produces SERVER_SENT_EVENTS, where each element is streamed individually.

However, when a JAX-RS endpoint returns Flow<T> with a regular content type (e.g., application/json), the response is semantically a collection of T. In that case, the generated schema should be an array (type: array, items: T), not a single T.

Current behavior:

@Path("items")
class ItemResource {
    @GET
    @Produces(APPLICATION_JSON)
    fun getItems(): Flow<Item> = flow { /* ... */ }
}

Generated schema for the 200 response:

"schema": {
  "$ref": "#/components/schemas/Item"
}

Expected behavior:

"schema": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/Item"
  }
}

Workaround:

Users can annotate the endpoint explicitly:

@APIResponse(
  responseCode = "200",
  content = [Content(
    mediaType = APPLICATION_JSON,
    schema = Schema(type = ARRAY, implementation = Item::class)
  )]
)
fun getItems(): Flow<Item>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions