Backend/SPRING

스웨거에서 노출되기를 원하지 않는 값들을 감추는 방법 / The way hides api property in Swagger

GreatSaiyaman 2022. 5. 31. 18:58

Spring에서 Swagger 작업을 하시다 보면, Client 개발자분에게 노출되지 않았으면 하는 값이 분명히 있을거라고 생각합니다. VO도 내부에서 쓰는 VO가 있을테니까요.

(물론 가장 좋은건, requestDTO와 responseDTO를 완전히 불리하고 해당 class를 구성하는 변수들까지도 깨끗하게 분리하는 것이곘지만요)

서론이 길었는데요, 결론은 간단합니다. hide처리하고 싶으신 값 위에 아래와 같이 적어주시면 됩니다.

@ApiModelProperty(hidden = true)

도움받은 링크도 같이 첨부합니다.

https://github.com/springfox/springfox/issues/554

 

@ApiModelProperty "hidden" attribute has no effect · Issue #554 · springfox/springfox

I'm including this annotation in my model, and there is one attribute there that I want to hide from the API, cause it's not relevant. As far as I know, "hidden" attribute of @Api...

github.com

위에서는 안된다고 되어있는데요.

제가 사용하고있는 swagger 기준(springfox-swagger2.3.0)에서는 의도한대로 잘 동작합니다.

감사합니다.