Responses
All generated endpoints return their java result type by default. This may be to simple for some endpoint implementations.
There are two mappings available to customize the result type:
-
If for example the response needs some customization we would like to use a
ResponseEntity<>
to modify it. This is possible using the result mapping. -
Another case is WebFlux, where we need the result to be either a
Flux<>
in case of an array type, or aMono<>
in case it is not an array type. This is possible using the single mapping.
single & result mappings are independent, i.e. both mappings can be used at the same
time. For example, it is possible to create a Mono<> result and modify the response using
ResponseEntity<> . The response type would be ResponseEntity<Mono<…>> .
|
result wrapper
A ResponseEntity<>
allows an endpoint implementation full control of
the response.
Here is a super simple examples:
public ResponseEntity<String> getFoo() {
return ResponseEntity.ok("foo");
}
To enable a result wrapper set the result
mapping in the mapping yaml to a fully qualified java
type.
map:
result: org.springframework.http.ResponseEntity
The processor expects that it takes a single generic parameter. |
Depending on the number of defined response content types the parameter of the ResponseEntity<>
will be either the java type or the unknown type.
responses | ResponseEntity<> |
---|---|
one |
|
multiple |
|
prior to 1.0.0.M13 all results were auto-wrapped with ResponseEntity<> .
|
See also result mapping.
single & multi wrapper
When using WebFlux we want to wrap certain parameters & results types in reactive types like
Mono<>
or Flux<>
.
To achieve this the processor knows two special mappings:
-
single: to wrap non-array like types (i.e. not a collection)
-
multi: to wrap array like types (i.e. a collection)