From 227064cd41862ef46f008cba72bebb364025aedb Mon Sep 17 00:00:00 2001 From: Nanajun22 Date: Sat, 2 May 2026 12:18:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Swagger=20=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 32 ++++++++-- .../comment/strategy/CommentStrategy.java | 2 +- .../domain/post/Service/PostService.java | 4 +- .../post/controller/PostController.java | 21 ++++--- .../post/controller/PostControllerDocs.java | 58 +++++++------------ .../domain/post/dto/PostRequestDto.java | 7 +-- .../{exception => error}/PostException.java | 2 +- .../post/strategy/PostReportStrategy.java | 2 +- .../controller/ReportAdminController.java | 4 +- .../controller/ReportAdminControllerDocs.java | 44 ++++++++++++++ .../report/controller/ReportController.java | 7 ++- .../controller/ReportControllerDocs.java | 45 ++++++++++++++ .../global/annotation/ApiErrorResponse.java | 2 + .../leets7th/global/code/ErrorCode.java | 14 ++++- .../global/config/SwaggerErrorCustomizer.java | 12 +++- .../global/error/GlobalExceptionHandler.java | 18 +++++- src/main/resources/application.properties | 7 +++ src/main/resources/data.sql | 9 +++ 18 files changed, 219 insertions(+), 71 deletions(-) rename src/main/java/com/example/leets7th/domain/post/{exception => error}/PostException.java (85%) create mode 100644 src/main/java/com/example/leets7th/domain/report/controller/ReportAdminControllerDocs.java create mode 100644 src/main/java/com/example/leets7th/domain/report/controller/ReportControllerDocs.java create mode 100644 src/main/resources/data.sql diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1c320137..c9d5fc2d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,24 @@ - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - diff --git a/src/main/java/com/example/leets7th/global/annotation/ApiErrorResponse.java b/src/main/java/com/example/leets7th/global/annotation/ApiErrorResponse.java index eb25f945..4cbd33ec 100644 --- a/src/main/java/com/example/leets7th/global/annotation/ApiErrorResponse.java +++ b/src/main/java/com/example/leets7th/global/annotation/ApiErrorResponse.java @@ -3,13 +3,13 @@ import com.example.leets7th.global.code.ErrorCode; -import com.example.leets7th.global.common.BaseCode; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; + @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ApiErrorResponse { diff --git a/src/main/java/com/example/leets7th/global/config/SwaggerErrorCustomizer.java b/src/main/java/com/example/leets7th/global/config/SwaggerErrorCustomizer.java index 396ae99a..a7c67a6b 100644 --- a/src/main/java/com/example/leets7th/global/config/SwaggerErrorCustomizer.java +++ b/src/main/java/com/example/leets7th/global/config/SwaggerErrorCustomizer.java @@ -13,10 +13,11 @@ import org.springframework.stereotype.Component; import org.springframework.web.method.HandlerMethod; + @Component public class SwaggerErrorCustomizer implements OperationCustomizer { - //에러코드 주입 + //Operation 커스터마이징 메서드 @Override public Operation customize(Operation operation,HandlerMethod handlerMethod) { @@ -34,7 +35,7 @@ public Operation customize(Operation operation,HandlerMethod handlerMethod) { String code = errorCode.getCode(); String message = errorCode.getMessage(); - // + //예시 응답 객체 세팅 Example example = new Example(); java.util.Map exampleValue = new java.util.LinkedHashMap<>(); exampleValue.put("success", false); @@ -43,18 +44,22 @@ public Operation customize(Operation operation,HandlerMethod handlerMethod) { example.setValue(exampleValue); - example.setDescription(message); - // + //현재 API 에서 응답 객체 가져오기 + /* + ApiResponses = ApiResponse 들의 컬렉션 + ApiResponse = 상태 코드 하나의 응답 정보를 담는 객체 + */ ApiResponses apiResponses = operation.getResponses(); ApiResponse apiResponse = apiResponses.containsKey(status) ? apiResponses.get(status) - : new ApiResponse().description(""); + : new ApiResponse().description(message); + //ApiResponse 객체 조립 Content content = apiResponse.getContent() != null ? apiResponse.getContent() : new Content(); MediaType mediaType = content.containsKey("application/json") ? content.get("application/json") : new MediaType();