Swagger 간단히 알아보기

정미·2021년 10월 9일
0

Swagger도 RestDocs와 마찬가지로 많이 사용되는 API 문서화 툴이다.

많이 쓰이지만 단점도 있음

  • production 코드와 문서화를 위한 코드가 섞이게 된다.
    • 운영 코드 해석이 힘들어짐
    • 유지보수 측면에서 좋지 않음
    @ApiOperation(value = "해당 게시판 조회") // documentation을 위한 annotation
     @ApiImplicitParams({
         @ApiImplicitParam(name = "id", value = "게시판 고유키", required = true, dataType = "string", paramType = "path", defaultValue = ""),
      })
      @RequestMapping(value = "/board/{id}", method = RequestMethod.GET)
      public ResultJson selectOneBoard(@PathVariable("id") Integer id) {
          ResultJson resultJson = new ResultJson();
          resultJson.setObject(boardService.selectOneBoard(id));
          resultJson.setResultCode(ResultCodeType.SUCCESS.getCode());
          resultJson.setMsg(ResultCodeType.SUCCESS.getMsg());
          return resultJson;
      }
  • RestDocs처럼 test를 하지 않아도 문서화를 하기 때문에 api 검증을 자동적으로 하지 못한다.

출처

0개의 댓글