question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Pageable should be broken down in its components and shouldn't be required

See original GitHub issue

Describe 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: Screenshot 2020-04-12 at 16 03 07

This is incorrect in different ways:

  • the arguments page, size and sort 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 is http://localhost:8080/api/v1/books?page=0&size=0&sort=string. However, this is confusing from a UX perspective, the page 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 the page, size, and sort 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
gotsoncommented, Apr 12, 2020

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.

3reactions
gotsoncommented, Apr 12, 2020

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found