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:

  1. 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.

  2. Another case is WebFlux, where we need the result to be either a Flux<> in case of an array type, or a Mono<> 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

since 1.0.0.M13

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

ResponseEntity<java type>

multiple

ResponseEntity<?>

prior to 1.0.0.M13 all results were auto-wrapped with ResponseEntity<>.

See also result mapping.

single & multi wrapper

since 1.0.0.M13

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)

multi

map:
  multi: reactor.core.publisher.Flux

Which will use Flux<> as collection wrapper instead of the original java collection type for all list responses (or parameters). The multi does not affect collections in model types.

single

To map non-array like responses to a Mono<> set the single mapping:

map:
  single: reactor.core.publisher.Mono

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