Issue
I have a simple SpringMVC controller
@RestController
@Validated
@RequestMapping("/users")
public class UsersController {
@GetMapping
public String getAllUsers(@Valid Filter filter) throws MyCustomServiceException {
[...]
}
}
Since this endpoint has around 20 RequestParam instead of bloating the controller(s) with all the fields I have put them all nicely in a POJO (that actually can be reused in other controllers that needs similar query params filters)
public class UserFilter extends GenericRequestParams {
[...]
private String email;
[...]
}
Now the problem is that Swagger doesn't consider that UserFilter
and its fields to be query params but a simple Object so on the Swagger UI it become useless since it's hard to test that endpoint.
Is there a way to instruct swagger that UserFilter
fields needs to be considered query params?
Solution
Magic annotation is @ParameterObject
@GetMapping
public String getAllUsers(@Valid @ParameterObject Filter filter) throws MyCustomServiceException {
[...]
}
Answered By - Alexis
Answer Checked By - Terry (JavaFixing Volunteer)