[Spring] Swagger에서 List형 명시?하기

19·2023년 9월 20일
0

Spring

목록 보기
25/29

배경

  • 반환은 List형태인데, 잘못 표기되어서 보여진다

Swagger를 사용해 반환형을 명시해주고 있는데, List형태는 어떻게 명시해주어야 하는지를 몰라서 찾아봤다
변경 이전의 코드는 아래와 같다

@Operation(...)
@ApiResponse(responseCode = "200", description = "팔로잉 조회 성공",
        content = {@Content(schema = @Schema(implementation = SampleResponse.class))})
public ResponseEntity<List<SampleResponse>> sampleMethod(...) {
    ...
}

내가 한 방법

결론은 @ApiResponse의 content 부분을 수정해주면 해결된다

content = {@Content(array = @ArraySchema(schema = @Schema(implementation = SampleResponse.class)))})
  • @ArraySchema를 사용해서 명시해줄 수 있다

  • 적용이 된 것을 확인
profile
하나씩 차근차근

0개의 댓글