是否可以在方法参数列表中的其他地方设置@RequestHeader注释?您可以在下面看到我的代码:
@ApiOperation("Gather all details of a specific device, identified by its ID")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = DeviceResource.class),
@ApiResponse(code = 404, message = "Device not found", response = VndErrors.class),
@ApiResponse(code = 500, message = "Printer shell execution error", response = VndErrors.class)
})
@GetMapping("/{id}")
public ResponseEntity<DeviceResource> getDeviceById(
@ApiParam(value = "ID of the device", required = true)
@PathVariable String id,
@RequestHeader(name = "X-NANO-APIKEY") String auth
) {
return ResponseEntity.ok(new DeviceResource(deviceAccessor.getDeviceById(id)));
}
问题是我也将该方法用于其他调用,因此我必须在此情境中设置标题。但我不想设置它。我只需要在swagger-ui中设置它。谢谢你的帮助。
答案 0 :(得分:0)
您也可以从HttpServletRequest对象中检索请求标头。
public ResponseEntity<DeviceResource> getDeviceById(
@ApiParam(value = "ID of the device", required = true)
@PathVariable String id,
HttpServletRequest request
) {
String auth = request.getHeader("X-NANO-APIKEY");
}
希望它有所帮助。