@springdoc Great contribution! But we're still having issues with Pageable.
Version: 1.2.17
The pageable-parameters are passed as
offset=0&pageNumber=0&pageSize=0&sort=sorted,true,unsorted,true,empty,true&paged=true&unpaged=true

_Originally posted by @NicklasWallgren in https://github.com/springdoc/springdoc-openapi/issues/177#issuecomment-563992434_
Hi,
as a Workaround i have hidden the Pageable param and add the parameters via annotation manually.
java
@GetMapping
@Operation(
parameters = {
@Parameter(in = ParameterIn.QUERY
, description = "Page you want to retrieve (0..N)"
, name = "page"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "0"))),
@Parameter(in = ParameterIn.QUERY
, description = "Number of records per page."
, name = "size"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "20"))),
@Parameter(in = ParameterIn.QUERY
, description = "Sorting criteria in the format: property(,asc|desc). "
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
, name = "sort"
, content = @Content(array = @ArraySchema(schema = @Schema(type = "string"))))
})
public PagedModel<EntityModel<..>> getIspContractsByContractSearch(@PageableDefault @Parameter(hidden = true) Pageable pageable) {
...
}
Thanks! Will use this workaround until solved
Created annotation to not have 15 lines of code in every pageable request. Hope it helps someone :)
@Target({METHOD, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Operation(parameters = {
@Parameter(in = ParameterIn.QUERY
, description = "Page you want to retrieve (0..N)"
, name = "page"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "0"))),
@Parameter(in = ParameterIn.QUERY
, description = "Number of records per page."
, name = "size"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "20"))),
@Parameter(in = ParameterIn.QUERY
, description = "Sorting criteria in the format: property(,asc|desc). "
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
, name = "sort"
, content = @Content(array = @ArraySchema(schema = @Schema(type = "string"))))
})
public @interface PageableOperation {
@AliasFor(annotation = Operation.class)
String summary() default "";
//... the other methods of Operation you use
}
@AnnaKarlsson Created annotation to not have 15 lines of code in every pageable request. Hope it helps someone :)
Cool, was looking for something like that. Thank you.
Hi guys,
You will have to declare explicit mapping of Pageable fields as Query Params and add the @Parameter(hidden = true) Pageable pageable on your pageable parameter.
You have started with some proposals. @Parameters annotation might be relevant, depending on your cases.
With the version 1.2.18, of springdoc-openapi, you can declare Pageable object as follow.
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Parameters({
@Parameter(in = ParameterIn.QUERY
, description = "Page you want to retrieve (0..N)"
, name = "page"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "0"))),
@Parameter(in = ParameterIn.QUERY
, description = "Number of records per page."
, name = "size"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "20"))),
@Parameter(in = ParameterIn.QUERY
, description = "Sorting criteria in the format: property(,asc|desc). "
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
, name = "sort"
, content = @Content(array = @ArraySchema(schema = @Schema(type = "string"))))
})
public @interface PageableAsQueryParam {
}
If we can come up with something more elegant we can add it directly to springdoc-openapi.
Most helpful comment
Hi,
as a Workaround i have hidden the Pageable param and add the parameters via annotation manually.
java @GetMapping @Operation( parameters = { @Parameter(in = ParameterIn.QUERY , description = "Page you want to retrieve (0..N)" , name = "page" , content = @Content(schema = @Schema(type = "integer", defaultValue = "0"))), @Parameter(in = ParameterIn.QUERY , description = "Number of records per page." , name = "size" , content = @Content(schema = @Schema(type = "integer", defaultValue = "20"))), @Parameter(in = ParameterIn.QUERY , description = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported." , name = "sort" , content = @Content(array = @ArraySchema(schema = @Schema(type = "string")))) }) public PagedModel<EntityModel<..>> getIspContractsByContractSearch(@PageableDefault @Parameter(hidden = true) Pageable pageable) { ... }