0

I already went through: How to define an optional parameter in path using swagger.

I've this endpoint:

@ApiOperation(value = "Retrieve Student Data By firstName Or lastName Or middleName",nickname = "Find Student Data")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully Retrieved Student Data"),
        @ApiResponse(code = 404, message = "No data found !!!") })
@GetMapping(path = "/firstName/{firstName}/lastName/{lastName}/middleName/{middleName}")
public GetStudentDataResponse getStudentData(@PathVariable(required = false) String firstName, @PathVariable(required = false) String lastName,@PathVariable(required = false) String middleName) {
    return service.getStudentData(firstName,lastName,middleName);
}

When I hit the rest endpoint and pass firstName only, Swagger is complaining about required parameter. How can we disabled it ?

enter image description here

Note: I really don't want to create another endpoint just to create / for the sake of to make it working via swagger.

PAA
  • 1
  • 46
  • 174
  • 282

1 Answers1

0

You need to use @RequestParam instead of @PathVariable. Then it allows you to make the Parameters optional.

PAA
  • 1
  • 46
  • 174
  • 282