Reputation: 2370
I am using Spring 2.3
and imported swagged using
implementation('io.springfox:springfox-swagger2:2.8.0')
implementation('io.springfox:springfox-swagger-ui:2.8.0')
I want to accept pagination params from the UI, and the model is
@Immutable
@JsonSerialize(as = ImmPaginationParameters.class)
@JsonDeserialize(as = ImmPaginationParameters.class)
public interface PaginationParameters {
Integer getLimit();
Integer getOffset();
}
In the controller I have declared the method as
@GetMapping("/preview")
@NonNull
ResponseEntity<List<SomeDto>> getPreviewResults(@PathVariable final String projectId,
@ModelAttribute final PaginationParameters params) {
However, the same does not get reflected in the Swagger UI.
I tried converting it into a post mapping and add @Valid
too in front of PaginationParameters
but the same thing. Checked the API docs, again no sign of pagination params. I checked the post What is @ModelAttribute in Spring MVC? and this way of defining modelAttribute looks sufficient. Not sure I have to declare something different in the PaginationParams class.
Upvotes: 2
Views: 1536
Reputation: 2370
Turns out that ModelAttribute doesn't work well with Immutable
class. After changing it to lombok, it worked
@Data
public class PaginationParameters {
private Integer limit;
private Integer offset;
}
Upvotes: -1
Reputation: 1023
Try using @RequestBody along with @ApiParam instead of @ModelAttribute, also use @Postmapping as you are passing request body :-
@PostMapping("/preview")
@NonNull
ResponseEntity<List<SomeDto>> getPreviewResults(@ApiParam @PathVariable final String projectId,
@ApiParam @RequestBody final PaginationParameters params) {
Upvotes: 2