Skip to content

Add support for @PageableDefault #831

Closed
@frankruegamer

Description

@frankruegamer

Describe the bug
Declaring a Pageable parameter with @PageableDefaults will not change the reported default values for page, size, sort in the OpenAPI definition.

To Reproduce

  • Enable pageable support with springdoc-openapi-data-rest or Pageable replacement with SpringDocUtils.
  • Add a controller and a method with a pageable paramater like so:
public Page<...> get(@ParameterObject @PageableDefault(size = 5, sort = "name") Pageable pageable) {}
  • The generated schema will look like this
[...]
- name: page
  in: query
  description: Zero-based page index (0..N)
  required: false
  schema:
    minimum: 0
    type: integer
    default: "0"
- name: size
  in: query
  description: The size of the page to be returned
  required: false
  schema:
    minimum: 1
    type: integer
    default: "20"
- name: sort
  in: query
  description: 'Sorting criteria in the format: property(,asc|desc). Default
    sort order is ascending. Multiple sort criteria are supported.'
  required: false
  schema:
    type: array
    items:
      type: string
[...]
  • calling the controller without specifying pageable parameters will correctly return 5 elements per page

Expected behavior
@PageableDefault should be recognized to change the defaults for Pageable in the schema.

Additional context

  • Using Springdoc v1.4.4, Spring Webflux 2.2.1.RELEASE.
  • Default of 20 seems to be coming from org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable#defaultPageSize.
  • Simply adding @PageableDefault without parameters is enough to change the returned elements per page from 20 to 10 (but not in the schema).
  • For WebFlux I also had to configure method argument resolvers:
@Configuration
public class AppConfiguration implements WebFluxConfigurer {

	@Override
	public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
		configurer.addCustomResolver(
				new ReactiveSortHandlerMethodArgumentResolver(),
				new ReactivePageableHandlerMethodArgumentResolver()
		);
	}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions