Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@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

like image 364
vijayakumarpsg587 Avatar asked Nov 06 '22 22:11

vijayakumarpsg587


1 Answers

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")
like image 128
Vladas Maier Avatar answered Nov 11 '22 15:11

Vladas Maier