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
Comments
Same issue with java spring generator when |
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. |
I can confirm the problem still exists in version |
Facing the same issue! Generator is creating the interface with Used version of openAPI GeneratorI am using 6.2.0, because 6.2.1 leads to a <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 Response1234 |
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 aDefaultApi.java
class returning aFlux<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.
The text was updated successfully, but these errors were encountered: