diff --git a/api/src/main/java/vook/server/api/web/swagger/GlobalOperationCustomizerImpl.java b/api/src/main/java/vook/server/api/web/swagger/GlobalOperationCustomizerImpl.java index b90fe2d..7054746 100644 --- a/api/src/main/java/vook/server/api/web/swagger/GlobalOperationCustomizerImpl.java +++ b/api/src/main/java/vook/server/api/web/swagger/GlobalOperationCustomizerImpl.java @@ -17,28 +17,12 @@ public class GlobalOperationCustomizerImpl implements GlobalOperationCustomizer @Override public Operation customize(Operation operation, HandlerMethod handlerMethod) { - applyDefaultOkApiResponse(operation); - applyUnauthorizedApiResponse(operation); - applyInternalServerErrorApiResponse(operation); + applyDefaultOkApiResponse(operation); //200 + applyUnauthorizedApiResponse(operation); //401 + applyInternalServerErrorApiResponse(operation); //500 return operation; } - private void applyUnauthorizedApiResponse(Operation operation) { - List security = operation.getSecurity(); - if (security == null) { - return; - } - - security.forEach(sr -> { - if (sr.containsKey("AccessToken")) { - operation.getResponses().computeIfAbsent( - "401", - k -> new ApiResponse().description("Unauthorized") - ); - } - }); - } - private void applyDefaultOkApiResponse(Operation operation) { ApiResponse apiResponse = operation.getResponses().computeIfAbsent( "200", @@ -63,17 +47,23 @@ private void applyDefaultOkApiResponse(Operation operation) { .addExamples("성공", new Example().$ref(ComponentRefConsts.Example.SUCCESS))); } - private static void applyInternalServerErrorApiResponse(Operation operation) { - MediaType jsonType = prepareOrGetJsonMediaType(operation); - - if (jsonType.getSchema() == null) { - jsonType.setSchema(new Schema<>().$ref(ComponentRefConsts.Schema.COMMON_API_RESPONSE)); + private void applyUnauthorizedApiResponse(Operation operation) { + List security = operation.getSecurity(); + if (security == null) { + return; } - jsonType.getExamples().put("처리되지 않은 서버 에러", new Example().$ref(ComponentRefConsts.Example.UNHANDLED_ERROR)); + security.forEach(sr -> { + if (sr.containsKey("AccessToken")) { + operation.getResponses().computeIfAbsent( + "401", + k -> new ApiResponse().description("Unauthorized") + ); + } + }); } - private static MediaType prepareOrGetJsonMediaType(Operation operation) { + private void applyInternalServerErrorApiResponse(Operation operation) { ApiResponse apiResponse = operation.getResponses().computeIfAbsent( "500", k -> new ApiResponse().description("Internal Server Error") @@ -85,10 +75,15 @@ private static MediaType prepareOrGetJsonMediaType(Operation operation) { MediaType jsonType = apiResponse.getContent().computeIfAbsent("application/json", k -> new MediaType()); + if (jsonType.getSchema() == null) { + jsonType.setSchema(new Schema<>().$ref(ComponentRefConsts.Schema.COMMON_API_RESPONSE)); + } + if (jsonType.getExamples() == null) { jsonType.setExamples(new HashMap<>()); } - return jsonType; + jsonType.getExamples().put("처리되지 않은 서버 에러", new Example().$ref(ComponentRefConsts.Example.UNHANDLED_ERROR)); } + }