Skip to content

Instantly share code, notes, and snippets.

@susimsek
Created January 13, 2021 10:13
Show Gist options
  • Select an option

  • Save susimsek/08263c43d6a17c61b53ed0aed8787d14 to your computer and use it in GitHub Desktop.

Select an option

Save susimsek/08263c43d6a17c61b53ed0aed8787d14 to your computer and use it in GitHub Desktop.
Spring boot Swagger Pagination
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.any())
.build()
.apiInfo(metaData())
.directModelSubstitute(Pageable.class,SwaggerPageable.class)
.useDefaultResponseMessages(false);
}
private ApiInfo metaData() {
return new ApiInfoBuilder()
.title("DAS REST API")
.description("\"Provides access to the core features of Digital Archiving System Rest Api.\"")
.version("1.0.0")
.build();
}
}
@Data
public class SwaggerPageable {
@ApiModelProperty(value = "Number of records per page",
dataType = "int",
example = "10"
)
private String size;
@ApiModelProperty(value = "Results page you want to retrieve (0..N)",
dataType = "int",
example = "0"
)
private String page;
@ApiModelProperty(
value = "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
dataType = "string"
)
private String sort;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment