Main Project (3)

김준영·2023년 7월 14일
1

Main-Project

목록 보기
3/4

pre project 진행할 때, API 문서화를 Spring Rest Docs를 사용했다.
하지만 무수한 많은 오류, 배포 시, 문서화에 관한 것들 때문에 Gradle build 조차 실패했다. 그래서 이번 메인 프로젝트에선 Swagger를 사용해보기로 했다.

@Api(value = "Feed API 컨트롤러", tags = "Feed API")
public class FeedController {

    private final FeedServiceImpl feedService;
    private final AuthenticationGetMemberId authenticationGetMemberId;
    private final FeedMapper feedMapper;

    @ApiOperation("피드 가져오기")
    @GetMapping("/{feed-id}")
    public ResponseEntity<FeedDto.Response> getFeed(@ApiParam("피드 아이디") @PathVariable("feed-id") long feedId) {
        long memberId = authenticationGetMemberId.getMemberId();
        FeedDto.Response response = feedService.getFeed(feedId, memberId);

        return ResponseEntity.ok(response);
    }

현재 메인 프로젝트 컨트롤러 코드 중 하나이다.

@Api를 통해 컨트롤러에 대해 작성하고, @ApiOperation을 통해 메서드에 관해 설명한다. @ApiParam을 통해 파라미터 설명을 한다.

반나절의 삽질을 한 끝에 문서화를 끝낼 수 있었다.

위 컨트롤러에만 스웨거 작업을 해주면 되는 줄 알았다...

그래서 실행한 결과, Request Body, Response Body가 뒤죽박죽 작성되어있었다...

그땐 몰랐었다. DTO에도 작성해줘야 하며 @ApiModel을 붙여 제대로 매핑을 해야한다는 것을....

	@Builder
    @Getter
    @ApiModel(value = "피드 생성용 DTO")
    public static class Post {
        @NotBlank
        @ApiModelProperty(value = "피드 내용", example = "피드 내용", required = true)
        private String content;
        @ApiModelProperty(value = "피드 이미지 파일", required = true)
        private List<MultipartFile> images;

    }

여튼, 마무리는 잘 됬다. 그리고 삽질을 했지만 사용 방법 또한 잘 흡수했다.

profile
ㅎㅎ

0개의 댓글