调用 Rest Endpoint 时如何在 Swagger 中使输入参数可选

How to make the input paramter option in Swagger while calling Rest 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);
}

当我到达其余端点并仅传递 firstName 时,Swagger 抱怨需要参数。我们怎样才能禁用它?

注意:我真的不想创建另一个端点只是为了创建/为了让它通过 swagger 工作。

您需要使用 @RequestParam 而不是 @PathVariable。然后它允许您将参数设为可选。