Skip to content

Commit c8f790c

Browse files
committed
#239, update single/multi documentation
1 parent 1ae6d86 commit c8f790c

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

docs/modules/ROOT/pages/mapping/single-multi.adoc

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
= (global) Single & Multi mapping
1+
:responseentity: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html
22

3-
NOTE: this is experimental
3+
= (global) Single & Multi mapping
44

55
== single & multi wrapper
66

@@ -38,6 +38,10 @@ map:
3838

3939
The processor will now wrap all non-array like response types with the given `single` mapping.
4040

41+
== endpoint specific mapping
42+
43+
it is also possible to configure `single` & `multi` on the xref:mapping/endpoint.adoc[endpoint level].
44+
4145

4246
== single & multi with result mapping
4347

@@ -57,3 +61,51 @@ and `multi`
5761
----
5862
ResponseEntity<Flux<String>>
5963
----
64+
65+
Unfortunately if you need the reactive result to modify the http response, something like this:
66+
67+
[source, java]
68+
----
69+
// does not work
70+
public ResponseEntity<Mono<Result>> someEndpoint() {
71+
return someBean.getResult()
72+
.map(r -> ResponseEntity
73+
.ok()
74+
.eTag(r.eTag())
75+
.body(Mono.just(r)));
76+
}
77+
----
78+
79+
it will not work because the result type of the statement is `Mono<ResponseEntity<Mono<Result>>>` and not the expected `ResponseEntity<Mono<Result>>`.
80+
81+
This can be fixed by modifying the response type to
82+
83+
[source, yaml]
84+
----
85+
openapi-processor-mapping: v6
86+
87+
options:
88+
# ...
89+
90+
map:
91+
# wrap the ResponseEntity with Mono
92+
result: reactor.core.publisher.Mono<org.springframework.http.ResponseEntity>
93+
94+
single: reactor.core.publisher.Mono
95+
multi: reactor.core.publisher.Flux
96+
----
97+
98+
which will now generate the endpoint signature as
99+
100+
[source, java]
101+
----
102+
public Mono<ResponseEntity<Mono<Result>>> someEndpoint() {
103+
// ...
104+
}
105+
----
106+
107+
and the above code will now work.
108+
109+
It is recommended to configure this on the endpoint level if you just need this for a few endpoints.
110+
111+
See also Spring link:{spring-responseentity}[`ResponseEntity`] documentation.

0 commit comments

Comments
 (0)