Reputation: 17
I have been asked to build a Rest endpoint that is a mix of path param and request param, looks like -
/user/{user}?refresh={refresh}
The request param should be optional.
I have tried String getUser(@PathVariable String user, @RequestParam Map<String, String> params);
but it makes the RequestParam mandatory (as it shows in Swagger UI).
How can I make it optional ?
Upvotes: 0
Views: 1946
Reputation: 130857
Set required
to false
in the @RequestParam
annotation, as follows:
@GetMapping("/user/{user}?refresh={refresh}")
String getUser(@PathVariable String user, @RequestParam(required = false) String refresh) {
...
}
Upvotes: 2