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>
kotlinx.coroutines.flow.Flowis currently registered as a wrapper type (similar toUniandCompletableFuture) inTypeUtil, which causes it to be unwrapped to its type parameterTand emitted as a single-element schema. This is correct behavior when the endpoint producesSERVER_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 ofT. In that case, the generated schema should be an array (type: array, items: T), not a singleT.Current behavior:
Generated schema for the
200response:Expected behavior:
Workaround:
Users can annotate the endpoint explicitly: