@AutoApiResponse 및 ApiResponseAdvice 제거 제안 #22
Kimgyuilli
started this conversation in
General
Replies: 1 comment
-
|
만약 DTO만 리턴하고 Advice가 래핑하는 방식으로 바꾸려면 모든 컨트롤러 코드를 고쳐야 하는데 현재 구조에서는 기술적으로 큰 이점이 없다고 생각합니다. 그리고 이미 모든 컨트롤러에서 CommonApiResponse.success 구조를 사용 중이기 때문에 리팩토링 리스크도 낮다고 생각해 제거하는게 맞는 것 같습니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
현재 프로젝트에서는 응답을 통일된 형식으로 반환하기 위해 두 가지 방식이 혼재되어 있습니다:
- @AutoApiResponse 어노테이션이 붙은 컨트롤러의 응답을 자동으로 CommonApiResponse로 래핑
- ResponseBodyAdvice 인터페이스를 구현하여 응답 전처리
- 모든 Controller 메서드에서 CommonApiResponse.success() 직접 호출
- 명시적으로 응답 객체 생성
@AutoApiResponse // ← 어노테이션은 있지만
@GetMapping("/{id}")
public CommonApiResponse getUser(@PathVariable Long id) {
return CommonApiResponse.success(SuccessCode.SUCCESS, response); // ← 수동 래핑
}
결과: ApiResponseAdvice의 래핑 로직이 실행되지만, 이미 CommonApiResponse로 래핑되어 있어 아무 작업도 하지 않고 통과만 합니다.
🚨 문제점
최근 PR 작업 중 @AutoApiResponse를 빠트리는 실수가 반복적으로 발생했습니다.
복잡도 증가:
기대했던 이점:
Controller 코드 간소화→ 실제로는 수동 래핑 사용 중일관된 응답 형식→ 수동 래핑으로도 충분히 달성가독성 향상→ 오히려 흐름이 암묵적이 되어 가독성 저하실제 상황:
// 기대: DTO만 반환
public UserResponseDto getUser(@PathVariable Long id) {
return userService.getUser(id);
}
// 실제: 수동 래핑 사용
public CommonApiResponse getUser(@PathVariable Long id) {
return CommonApiResponse.success(SuccessCode.SUCCESS, response);
}
현재 방식의 제약:
수동 래핑 시의 장점:
💡 제안
@AutoApiResponse와 ApiResponseAdvice를 완전히 제거하고, Controller에서 명시적으로 CommonApiResponse를 반환하는 방식으로 통일
변경 사항
삭제할 파일:
Controller 수정:
@AutoApiResponse
@RestController
public class UserController {
}
유지되는 부분
✨ 기대 효과
📊 Before / After 비교
🤔 의견 부탁드립니다
이 제안에 대해 팀원 분들의 의견을 듣고 싶습니다:
참고: 실제 동작 분석
현재 ApiResponseAdvice의 실제 동작:
public Object beforeBodyWrite(Object body, ...) {
if (body instanceof CommonApiResponse) {
return body; // ← 항상 여기서 그냥 통과!
}
// 아래 코드는 실행되지 않음
return CommonApiResponse.success(SuccessCode.SUCCESS, body);
}
결론: 복잡도만 추가하고 실제로는 아무 역할도 하지 않는 상태입니다.
Beta Was this translation helpful? Give feedback.
All reactions