7

Below is a code that is similar to the situation I have

@ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "OK", content = {@Content(schema = @Schema(
                implementation =  // <-- What to specify here?
            ))})
})
@GetMapping(value = "/user")
public ResponseEntity<List<User>> getUsers() {
    return ResponseEntity.ok().body(Arrays.asList(new User(), new User()));
}

How do I specify the list of Users being returned from the endpoint in ApiResponse()?

Please note that the Open-API-Definition is not part of the project, but is specified in another project.

Debargha Roy
  • 2,320
  • 1
  • 15
  • 34

1 Answers1

11

Solved using the below method

@ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "OK", content = {
                @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))
            })
})
@GetMapping(value = "/user")
public ResponseEntity<List<User>> getUsers() {
    return ResponseEntity.ok().body(Arrays.asList(new User(), new User()));
}
Debargha Roy
  • 2,320
  • 1
  • 15
  • 34