[Java] [Spring] Fix reactive return type for list (#16884)

* Improve Add Async - Spring Cloud test

By testing the generated code.
This will be used to detect regressions.

* Spring: Fix reactive return type for list

Fix for #16883.

When *reactive* is enabled and response entities is *disabled*,
use `Flux<Item>` to stream the output instead of `Mono<Flux<Item>>`
With Spring Reactive, the expected return type for an array of item is
`Flux<Item>`.
Without this patch, the generated code is `Mono<Flux<Item>>`.

This is fixed by introducing specific handling for return types when
reactive is enabled.
In particular, "responseWrapper" is not used anymore in such situations.

* Fix methodBody

* Fix invalid test

* Fix SSE

* Fix methodBody when isArray and useResponseEntity

* methodBody: Flux.empty() instead of s -> {}
This commit is contained in:
Vladimir Svoboda
2024-03-02 14:19:34 +01:00
committed by GitHub
parent 009fda5e3d
commit 5d43c88540
8 changed files with 72 additions and 18 deletions

View File

@@ -146,7 +146,7 @@ public interface PetApi {
)
@ResponseStatus(HttpStatus.OK)
default Mono<Flux<Pet>> findPetsByStatus(
default Flux<Pet> findPetsByStatus(
@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) List<String> status,
@ApiIgnore final ServerWebExchange exchange
) {
@@ -189,7 +189,7 @@ public interface PetApi {
)
@ResponseStatus(HttpStatus.OK)
default Mono<Flux<Pet>> findPetsByTags(
default Flux<Pet> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) Set<String> tags,
@ApiIgnore final ServerWebExchange exchange
) {

View File

@@ -76,7 +76,7 @@ public interface PetApiDelegate {
* or Invalid status value (status code 400)
* @see PetApi#findPetsByStatus
*/
default Mono<Flux<Pet>> findPetsByStatus(List<String> status,
default Flux<Pet> findPetsByStatus(List<String> status,
ServerWebExchange exchange) {
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
@@ -92,7 +92,7 @@ public interface PetApiDelegate {
break;
}
}
return result.then(Mono.empty());
return result.thenMany(Flux.empty());
}
@@ -107,7 +107,7 @@ public interface PetApiDelegate {
* @see PetApi#findPetsByTags
*/
@Deprecated
default Mono<Flux<Pet>> findPetsByTags(Set<String> tags,
default Flux<Pet> findPetsByTags(Set<String> tags,
ServerWebExchange exchange) {
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
@@ -123,7 +123,7 @@ public interface PetApiDelegate {
break;
}
}
return result.then(Mono.empty());
return result.thenMany(Flux.empty());
}