How to represent List of Strings in Springdoc Swagger v3?

Viewed 2100

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.

1 Answers

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()));
}
Related