[Swagger/warn] Illegal DefaultValue null for parameter type integer

강신현·2022년 10월 5일
0

문제

빌드시 문제가 발생하지 않지만 swagger을 실행하면 warn이 발생한다.

- Illegal DefaultValue null for parameter type integer
- java.lang.NumberFormatException:For input string:""


원인

Primitive type인 int, long 타입에는 null 값이 들어갈 수 없기 때문이다.


해결

@ApiImplicitParam 속성으로 example = "0" 값을 넣어 기본값을 정해주면 된다.

  • 수정 전
@ApiOperation(value = "유저 Profile 조회")
@ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class)
@GetMapping("/prifile/{userId}")
public ApplicationResponse<UserProfileRes> getProfile(@PathVariable Long userId){
    return userService.getProfile(userId);
}
  • 수정 후
@ApiOperation(value = "유저 Profile 조회")
@ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0")
@GetMapping("/prifile/{userId}")
public ApplicationResponse<UserProfileRes> getProfile(@PathVariable Long userId){
    return userService.getProfile(userId);
}

https://yju7257.tistory.com/130

profile
땅콩의 모험 (server)

0개의 댓글