아래와 같이 build.gradle을 셋팅해놓고 swagger를 사용 중이었다.
...
dependencies {
...
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'io.springfox:springfox-swagger2:2.9.2'
}
...
그런데 swagger ui에서 테스트를 하거나, 새로고침만 해도 java.lang.NumberFormatException: For input string: "" ~ 라는 메세지가 나타났다. 동작은 되긴하지만 뭐가 문제인지는 해결하고 넘어가야 될 거 같아서 찾아보았다.
방법 1.
swagger2의 swagger-annotations와 swagger-models에서 문제가 발생하는 것이라고 한다.
아래와 같이 문제가 되는 부분을 제거하고, 해당 부분은 다운그레이드하여 실행하니 예외 메시지가 없어졌다.
...
dependencies {
...
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation('io.springfox:springfox-swagger2:2.9.2') {
exclude module: 'swagger-annotations'
exclude module: 'swagger-models'
}
implementation 'io.swagger:swagger-annotations:1.5.21'
implementation 'io.swagger:swagger-models:1.5.21'
}
...
근데 찜찜하다.
이유가 있으니 버전 업을 했을텐데 그 중에 일부만 다운그레이드해서 사용하는 게 좋은 방법일까?
방법 2.
업그레이드 된 버전에 맞춰서 사용하는 것이 맞는 것 같다.
파라미터 타입이 int인 경우, 아래와 같이 @ApiImplicitParam에 example을 추가해주면 된다.
@ApiImplicitParam(... example = "1"),
코드에 덕지덕지 뭐가 붙는 게 싫어서 example 웬만하면 안 넣었는데... 다 찾아서 넣어줘야지 행복해
참고
https://github.com/springfox/springfox/issues/2265 → 다운그레이드
@ApiModelProperty throwing NumberFormatException if example value is not set · Issue #2265 · springfox/springfox
Hi, When we don't set example value in @ApiModelProperty for Wrapper class, its try to set empty string ("") as an example and during parsing its throw NumberFormatException, can'...
github.com
https://onethejay.tistory.com/111 → @ApiImplicitParam에 example 사용
swagger-ui 에러 java.lang.NumberFormatException: For input string: ""
Swagger-ui 상위 버전 사용시 나타나는 java.lang.NumberFormatException: For input string: "" 에러에 대해 댓글로 정리해두신 분이 있어서 가져와 정리했습니다. 출처 : https://lemontia.tistory.com/1000#com..
onethejay.tistory.com
'프로젝트 > 기타' 카테고리의 다른 글
[문서자동화] swagger, gradle (0) | 2022.07.30 |
---|