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

[BUG] [kotlin-spring] in reactive mode Flow<String> is not the same as Mono<List<String>>

Open pschichtel opened this issue 4 years ago • 4 comments

Description

The generator triggers an unfortunate behavior in Spring when the response of an operations is an array of plain strings. in that case the generator produces Flow<String> which spring will assume to be raw JSON and concatenate.

See this issue: https://github.com/spring-projects/spring-framework/issues/20807

openapi-generator version

5.2.0

OpenAPI declaration file content or url
openapi: 3.0.0
paths:
  /itu/details:
    get:
      operationId: someOp
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
Generation Details

The generator is kotlin-spring with delegatePattern = false. The generated operation method in the controller interface will have return type of Flow<String>, however according to the issue linked about this is not equivalent to List<String>.

So instead of:

fun someOp(): Flow<String>

it should generate something like

suspend fun someOp(): List<String>

as suggested by the issues. This is only necessary for a few specific "low-level" types like String and ByteArray.

pschichtel avatar Aug 24 '21 16:08 pschichtel

Hi The same behavior happens with the Spring Java generator.

As @pschichtel says, maybe it would be nice to define the input parameters and return type as List<String> instead of Flux<String> when the type is a String (with other types, maintain the Flux)

jorgerod avatar Oct 01 '21 07:10 jorgerod

Any advance?

MiguelAngelLV avatar Jul 10 '23 12:07 MiguelAngelLV

+1

jeferro avatar Dec 06 '23 22:12 jeferro

Any update regarding it? I was really surprised that my tests failed when switched reactive to true because of this serialisation.

jacaczapBright avatar Apr 22 '24 08:04 jacaczapBright