Swagger documentation for Spring Pageable interface Swagger documentation for Spring Pageable interface spring spring

Swagger documentation for Spring Pageable interface


This is a known issue with Spring-Fox. See Issue #755. Based on zdila's comment 2 at this time alternative is to add @ApiImplicitParams which is not ideal but it does work.

@ApiImplicitParams({    @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query",            value = "Results page you want to retrieve (0..N)"),    @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query",            value = "Number of records per page."),    @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",            value = "Sorting criteria in the format: property(,asc|desc). " +                    "Default sort order is ascending. " +                    "Multiple sort criteria are supported.")})

[Swagger UI showing @ApiImplicitParams for Pageable]

1 https://github.com/springfox/springfox/issues/755

2 https://github.com/springfox/springfox/issues/755#issuecomment-135059871


Building on Vineet Bhatia's answer, you can wrap the solution up in a custom annotation for reusability:

@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE })@Retention(RetentionPolicy.RUNTIME)@ApiImplicitParams({    @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", value = "Results page you want to retrieve (0..N)"),    @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", value = "Number of records per page."),    @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). "            + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })@interface ApiPageable {}

Which can then be used like so:

@ApiPageablepublic Page<Data> getData(Pageable pageRequest) {


Vineet Bhatia's answer with @ApiImplicitParams looks fine. But I faced with situation, when @ApiIgnor and @ApiParam(hidden = true) doesn't work and you can still observe the asembler and pageable params. I fixed this problem by adding next line

docket.ignoredParameterTypes(Pageable.class, PagedResourcesAssembler.class);

to the Docket bean in my SwaggerConfig.