I’m using SpringBoot with OpenAPI and SwaggerUI to implement a rest api. I want to annotate a @GetMapping method with @ApiResponses to provide the schema of the response, but I’m struggling with the parameter implementation of @Schema. The return type of my method is List<ScanDTO>, so I tried the following:
@ApiResponses( value = {
@ApiResponse(content = {@Content(schema = @Schema(implementation = List<ScanDTO>.class))})
})
But this doesn’t work. Things like ScanDTO.class would work. The implementation argument is of type Class<?>.
My workaround would be to create a wrapper class like the following:
public interface ScanDTOList extends List<ScanDTO> {
}
and use it. It seems to be working, but I think I wont need that additional class in the future, so I am wondering, if there is any way to get this working without this workaround.
Advertisement
Answer
Using ArraySchema should solve this for you
@ApiResponse(
content = {@Content(
array = @ArraySchema(schema = @Schema(implementation = ScanDTO.class))
)}
)