Springdoc Data REST ignore overwrite Pageable parameters name
In my application.properties, I have overwritten the name of the Pageable parameters:
spring.data.web.pageable.page-parameter=offset
spring.data.web.pageable.size-parameter=limit
But when I go to the Swagger UI to check my Swagger documentation, the new name parameters are not used:
Here is the signature of my function:
@PageableAsQueryParam
@Operation(summary = "")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomPage.class))),
@ApiResponse(responseCode = "404", description = "", content = @Content)
})
@GetMapping(path = "/{version}/foo", produces = MediaType.APPLICATION_JSON_VALUE)
@Override
public ResponseEntity<CustomPage<ReducedAsset>> getAll(@ParameterObject Pageable pageable,
@Parameter(description = "Version from which to get the list")
@PathVariable String version)
How can I bind the new name to the documentation? And can I change the default description?
Thanks for your answer!
Solution 1:
Simplest & less intrusive approach would be probably:
package com.example.springdocdatarest;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Parameter(in = ParameterIn.QUERY,
description = "Zero-based page index (0..N)",
name = "offset", // !
schema = @Schema(type = "integer", defaultValue = "0"))
@Parameter(in = ParameterIn.QUERY,
description = "The size of the page to be returned",
name = "limit", // !
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",
array = @ArraySchema(schema = @Schema(type = "string")))
public @interface MyPageableAsQueryParam {
}
- Copying from https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/core/converters/models/PageableAsQueryParam.java
- Replacing with the values we want. (also description;)
And using it:
@com.example.springdocdatarest.MyPageableAsQueryParam
@Operation(summary = "") // ...
@GetMapping ...
Test (switching version and Pageable parameter (order;)):
Note
There are also:
spring.data.rest.page-param-name=foo
spring.data.rest.limit-param-name=bar
spring.data.rest...
spring-data-rest properties for "these".