Conversation
… standardized error responses
…ng with new ResponseCode mappings and adjust schema reference to ApiResponseDtoVoid
|
chwwwon
reviewed
Jan 22, 2026
| voidSchema.addProperty("data", dataSchema); | ||
|
|
||
| // 스키마 등록 | ||
| openApi.getComponents().addSchemas("ApiResponseDtoVoid", voidSchema); |
Contributor
There was a problem hiding this comment.
openApi.getComponents()가 null일 경우 NPE가 발생할 수 있어 Components 존재 여부 검사/초기화 후 addSchemas 사용하도록 수정이 필요하다고 합니다
// 사용하는 버전에 따라 addProperties 사용 또는 Map으로 setProperties
voidSchema.addProperties("code", codeSchema);
voidSchema.addProperties("message", messageSchema);
voidSchema.addProperties("data", dataSchema);
openApi.getComponents().addSchemas("ApiResponseDtoVoid", voidSchema);
Contributor
There was a problem hiding this comment.
addProperties 메서드
Map<String, Schema> props = new LinkedHashMap<>();
props.put("code", codeSchema);
props.put("message", messageSchema);
props.put("data", dataSchema);
voidSchema.setProperties(props);
- openApi.getComponents() null 가능성으로 인한 NPE 방지 - Swagger v3 버전 의존적인 addProperty() 사용 제거 → 컴파일 안정성 확보 - Map + setProperties() 방식으로 모든 환경에서 안전하게 스키마 등록 기능/설계 변경 없이 안정성 보완만 수행
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


🔗 Related Issue
📝 Description
기획 배경 및 비즈니스 문제
🛠 Changes
1. Swagger 응답 모델 최적화 (Generic Type 지원)
ApiResponseDto스키마 설정 수정:@Schema(name = "ApiResponseDto")선언을 삭제했습니다.T)을 분석하여ApiResponseDtoUserResponseDto와 같이 타입별로 고유한 스키마를 생성하도록 개선했습니다.2. 에러 응답 전용 스키마(
ApiResponseDtoVoid) 도입OpenApiConfig스키마 명시적 등록:OpenApiCustomizer를 통해ApiResponseDtoVoid스키마를 공통 컴포넌트에 등록했습니다.data필드가 항상null이므로ApiResponseDto<Void>형태를 표준으로 정의했습니다.SwaggerErrorCodeExampleCustomizer수정 (68-73라인):#/components/schemas/ApiResponseDto→#/components/schemas/ApiResponseDtoVoid로 변경하여 성공 응답 모델과의 간섭을 차단했습니다.CANNOT_ADD_DIARY_TO_PAST_TRIP등 누락되었던ErrorCode매핑 로직을 추가했습니다.3. 컨트롤러 응답 정의 규칙 통일
모든 컨트롤러 API 명세를 아래 표준 규칙에 맞춰 리팩토링했습니다.
ResponseEntity<ApiResponseDto<T>>적용@ApiResponse내content속성 제거content = @Content속성 유지SwaggerErrorCodeExampleCustomizer가 커스텀 에러 예시를 주입하도록 보장✅ Test Checklist