Search code examples
spring-bootswaggerspringfox

@ApiResponse swagger springfox - use of custom response container


I am trying to display a custom container as a success response in swagger. I am unable to describe the desired model for this

@ApiResponse (code = 200, message = "Successfully retrieved report info", response = PagedResponse.class

THis PagedResponseInfo is actually a custom collection

public class PagedResponse<T> {

    private long page;
    private long pageSize;
    private long totalRecords;
    private List<T> records;
}

How do I specify the container for this if it were to contain a collection of Report objects in it? Could someone help me out please? I use springfox swagger -2.9.2 in spring boot


Solution

  • You need to define the responseContainer attribute in the @ApiResponse annotation.

    /**
     * Declares a container wrapping the response.
     * <p>
     * Valid values are "List", "Set" or "Map". Any other value will be ignored.
     */
    String responseContainer() default "";
    

    The value List is what you are looking for. It will wrap your PagedResponse<ReportInfo> in a container.

    @ApiResponse(
        code = 200,
        message = "Successfully retrieved report info",
        response = PagedResponse.class,
        responseContainer = "List")