Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ] Handle list of String special case in webclient generator #7118

Closed
dlicois opened this issue Aug 3, 2020 · 4 comments · Fixed by #16326
Closed

[REQ] Handle list of String special case in webclient generator #7118

dlicois opened this issue Aug 3, 2020 · 4 comments · Fixed by #16326

Comments

@dlicois
Copy link

dlicois commented Aug 3, 2020

Is your feature request related to a problem? Please describe.

When describing an operation that returns an array of string, the openapi-generator for java-webclient generates an api returning a Flux<String>.

However Spring's Webclient handles serialization of JSON array of strings in a special way : spring-projects/spring-framework#22662

This means expecting a Flux<String> when a server return an array of String is a mistake.

Please see sample Gradle project https://github.com/dlicois/webclient-liststring, it contains a test class (WebClientListStringTest.java) to better explain the behaviour.
The openapi.yaml describes an operation returning an array of string, openapi-generator generates a DefaultApi.java class returning a Flux<String>.
When the webclient receive the answer ["one","two", "three"], it publishes a single String of value ["one","two", "three"].
I would have expected three Strings.

This makes the generated api unusable for this case, requiring to parse the response a second time to handle it.

Describe the solution you'd like

Recommended solution by Spring developers (see spring-projects/spring-framework#22662 and https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-codecs-jackson) is to use a Mono<List> for string arrays.

This would mean making a special case for operations described as arrays of string to generate a Mono<List> instead of Flux.

@bossqone
Copy link

Same issue with java spring generator when @RequestBody is used with Flux<String> to parse json request ["a", "b", "c"].

@garzy
Copy link

garzy commented May 5, 2022

I'm having the same issue ¿won't be fixed yet in 2022? this issue was opened in 2020, please fix them

I'm generating WebClient code with the 5.4.0 version of open API-generator cli.

@yasammez
Copy link
Contributor

yasammez commented Nov 7, 2022

I can confirm the problem still exists in version 6.2.1 of openapi-generator. For now, the only option seems to be to wrap the array in a useless JSON object (that is, if you control the API as well as the implementation).

@giftkugel
Copy link

giftkugel commented Jan 26, 2023

Facing the same issue!

Generator is creating the interface with Mono<ResponseEntity<Flux<String>>>

Used version of openAPI Generator

I am using 6.2.0, because 6.2.1 leads to a OutOfMemoryError 🤷

                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.2.0</version>
...
                            <generatorName>spring</generatorName>
                            <library>spring-boot</library>

Response defined in openAPI YAML

      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

Generated Controller/Interface

        default Mono<ResponseEntity<Flux<String>>> foo(...,ServerWebExchange exchange)

Expected JSON Response

["1", "2", "3", "4"]

Current JSON Response

1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment