Reputation: 12015
I'm looking to develop the Spring Boot + OpenAPI 3 example by taking a look at the https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/ and https://techsparx.com/software-development/openapi/spring-boot-rest-api-docs.html. In this example, I am looking to pass the pagination details through Swagger UI that I got by adding the springdoc-openapi-ui
.
What Spring Boot Configurations do I need to do in order to support custom pagination.?
Upvotes: 4
Views: 8858
Reputation: 41
"The support for Pageable of spring-data-commons is available out-of-the box since springdoc-openapi v1.6.0. For this, you have to combine @ParameterObject
annotation with the Pageable
type." - Source
Assuming you are using springdoc-openapi v1.6.0 or grater, you could do something like this:
@GetMapping("/foo")
public Page<Foo> getFoo(@ParameterObject Pageable pageable) {
// do something
}
Upvotes: 4
Reputation: 355
Their is more than one possiblity the simpliest and fastest is if only want to enable the support of spring Pageable Type, you can just enable it using:
SpringDocUtils.getConfig().replaceWithClass(org.springframework.data.domain.Pageable.class,
org.springdoc.core.converters.models.Pageable.class);
Alternately, the projects that use Pageable type can aslo add the follwing dependency together with the springdoc-openapi-ui dependency. This dependency enables the support of spring-data-rest types as well: @RepositoryRestResource and QuerydslPredicate annotations.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.5.6</version>
</dependency>
And the add @ParameterObject on the Pageable object on your controller method.
@GetMapping("/books")
public ResponseEntity<List<BookDTO>> getBooks(@ParameterObject Pageable pageable)
Upvotes: 4
Reputation: 78
Add @PageableAsQueryParam annotation on the method and add springdoc-openapi-data-rest as a dependency
Upvotes: 4