Spring Pageable should be broken down in its components and shouldn't be required
See original GitHub issueDescribe the bug When using a Pageable in its simple form:
@GetMapping("api/v1/books")
fun getAllBooks(page: Pageable)
it results in the following in the Swagger UI:
This is incorrect in different ways:
- the arguments
page
,size
andsort
can be passed individually, not necessarily all at once, and not in an object form. I agree that when setting the object, the resulting URL ishttp://localhost:8080/api/v1/books?page=0&size=0&sort=string
. However, this is confusing from a UX perspective, thepage
parameter is marked as an object, while this is clearly wrong. Spring maps 3 optional parameters to an internal object. Also the defaults are applied by Spring automatically, not at the request level, so those parameters should default to being empty. - the parameter
page
is marked as required, while it is definitely not true. Not passing any of thepage
,size
, andsort
parameters result in valid queries. - the default value of the
sort
parameter in the object ("string"
) makes the default behavior when trying out to fail, as no field or property"string"
is defined on the underlying repository. This is more a comment on the current behaviour. If it was working properly with 3 different optional parameters with no default value, it would work as expected.
To Reproduce Steps to reproduce the behavior:
- What version of spring-boot you are using?
2.2.5.RELEASE
- What modules and versions of springdoc-openapi are you using?
org.springdoc:springdoc-openapi-ui:1.3.1
org.springdoc:springdoc-openapi-data-rest:1.3.1
org.springdoc:springdoc-openapi-security:1.3.1
org.springdoc:springdoc-openapi-kotlin:1.3.1
- What is the actual and the expected result using OpenAPI Description (yml or json)? I am only looking at the resulting Swagger UI
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Spring Data JPA Pagination without count query
Based on the logs, the count query appears to issued when I try this, too (even for page 1). Makes me question the...
Read more >Spring Data JPA Tutorial: Pagination - Petri Kainulainen
This blog post describes how you can paginate your query results with Spring Data JPA.
Read more >Spring Data Commons - Reference Documentation
This section covers the fundamentals of Spring Data object mapping, object creation, field and property access, mutability and immutability.
Read more >Paging with Spring Boot - Reflectoring
If we want to return a Page (or Slice ) of items in a web controller, it needs to accept a Pageable parameter...
Read more >Pagination with Spring Data JPA
While calling the above method, you need to create an object of Pageable and pass it to the invoked repository method. The simplest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I understand your point, but I am dubious about the use you mention, because Pageable in Spring is a repository convenience, with argument resolvers to map the 3 params to an instance of Pageable when passed in a url.
Maybe we could have a globale configuration property to switch the behavior to something similar to what @ParameterObject does, but without having to specify the annotation on each and every Pageable in the application.
Even better, this configuration could be set to true by default, and if someone really want to use a Pageable as an object parameter, they could change the configuration to false.
What I don’t understand is why there is a need for those annotations? The default behavior should be to show 3 parameters that are optional, same as with
I don’t understand which use case does the default address exactly, would you be able to explain in which instance would someone want to have a Pageable object in their api specification, which doesn’t exist as parameter in Spring?