From 5b3068238f355b75980929cbb696ba23fadd9cf0 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Tue, 18 Apr 2023 17:05:32 +0900 Subject: [PATCH] feat: swagger2 set --- pom.xml | 6 +- .../biz/cache/web/CacheController.java | 26 +++- .../biz/mng/code/dto/XitDetailCodeMngVO.java | 6 + .../mng/code/web/CodeDtlMgtController.java | 18 ++- .../xit/framework/core/aop/LogAopAdvice.java | 2 +- .../framework/core/config/Swagger2Config.java | 123 ++++++++++++++---- .../resources/props/local/globals.properties | 1 + 7 files changed, 147 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 8ef7ec2e..4872d3e8 100644 --- a/pom.xml +++ b/pom.xml @@ -215,12 +215,16 @@ springfox-swagger2 2.9.2 - io.springfox springfox-swagger-ui 2.9.2 + + io.swagger + swagger-annotations + 1.6.10 + diff --git a/src/main/java/kr/xit/framework/biz/cache/web/CacheController.java b/src/main/java/kr/xit/framework/biz/cache/web/CacheController.java index 33bb4d54..2ab4eea0 100644 --- a/src/main/java/kr/xit/framework/biz/cache/web/CacheController.java +++ b/src/main/java/kr/xit/framework/biz/cache/web/CacheController.java @@ -1,5 +1,9 @@ package kr.xit.framework.biz.cache.web; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import kr.xit.framework.biz.mng.bbs.dto.XitBasicBbsMngSearchVO; import kr.xit.framework.support.util.ConvertUtils; import org.springframework.stereotype.Controller; @@ -16,18 +20,22 @@ import java.util.Map; * 공통코드, 사용자코드 콘트롤러 * */ +@Api(value="Cache Controller", tags = "CacheController") @Controller @RequestMapping(value="/framework/biz/cmm/cache") -public class -CacheController { +public class CacheController { /** * 코드 목록조회 * @param codeId String * @return ModelAndView */ + + @ApiOperation(value = "공통 코드 목록 조회", notes = "공통 코드 목록 조회") + @ApiImplicitParam(name = "codeId", value = "공통코드 ID", required=true, paramType = "query", dataTypeClass = String.class, defaultValue = "FIM001") @GetMapping(value="/getCodeList") - public ModelAndView getCodeList(final String codeId) { + public ModelAndView getCodeList( + final String codeId) { ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW); mav.addObject("comboList", CacheServiceUtils.getCodes(codeId)); return mav; @@ -38,15 +46,23 @@ CacheController { * @param codeId String * @return ModelAndView */ + @ApiOperation(value = "공통 콤보 코드 목록 조회", notes = "공통 콤보 코드 목록 조회") + @ApiImplicitParam(name = "codeId", value = "공통코드 ID", required=true, paramType = "query", dataTypeClass = String.class, defaultValue = "FIM001") @GetMapping(value="/getComboCodeList") - public ModelAndView getComboCodeList(final String codeId) { + public ModelAndView getComboCodeList( + final String codeId) { ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW); mav.addObject("comboList", CacheServiceUtils.getComboCodes(codeId)); return mav; } + @ApiOperation(value = "공통 콤보 코드(타입) 목록 조회", notes = "공통 콤보 코드(타입) 목록 조회") + @ApiImplicitParams ({ + @ApiImplicitParam(name = "codeId", value = "공통코드 ID", paramType = "query", dataTypeClass = String.class, defaultValue = ""), + @ApiImplicitParam(name = "type", value = "타입", required = true, paramType = "query", dataTypeClass = String.class, defaultValue = "AUTHOR_GRP") + }) @GetMapping(value="/getComboCodeTypeList") - public ModelAndView getComboCodeTypeList(final String codeId, final String type) { + public ModelAndView getComboCodeTypeList(final String codeId, final String type) { ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW); mav.addObject("comboList", CacheServiceUtils.getComboCodes(codeId, type)); return mav; diff --git a/src/main/java/kr/xit/framework/biz/mng/code/dto/XitDetailCodeMngVO.java b/src/main/java/kr/xit/framework/biz/mng/code/dto/XitDetailCodeMngVO.java index 52ae7903..ab04ba64 100644 --- a/src/main/java/kr/xit/framework/biz/mng/code/dto/XitDetailCodeMngVO.java +++ b/src/main/java/kr/xit/framework/biz/mng/code/dto/XitDetailCodeMngVO.java @@ -1,5 +1,6 @@ package kr.xit.framework.biz.mng.code.dto; +import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -35,26 +36,31 @@ public class XitDetailCodeMngVO { /* * 코드ID */ + @ApiParam(value = "코드 ID", required = true) private String codeId; /* * 코드ID명 */ + @ApiParam(value = "코드 ID 이름") private String codeIdNm; /* * 코드 */ + @ApiParam(value = "코드") private String code; /* * 코드명 */ + @ApiParam(value = "코드 이름") private String codeNm; /* * 코드설명 */ + @ApiParam(value = "코드 설명") private String codeDc; private String etc1; diff --git a/src/main/java/kr/xit/framework/biz/mng/code/web/CodeDtlMgtController.java b/src/main/java/kr/xit/framework/biz/mng/code/web/CodeDtlMgtController.java index 23a60b05..5af35386 100644 --- a/src/main/java/kr/xit/framework/biz/mng/code/web/CodeDtlMgtController.java +++ b/src/main/java/kr/xit/framework/biz/mng/code/web/CodeDtlMgtController.java @@ -2,12 +2,17 @@ package kr.xit.framework.biz.mng.code.web; import java.util.Map; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; import kr.xit.framework.support.util.Checks; + import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @@ -21,20 +26,25 @@ import kr.xit.framework.support.util.AjaxMessageMapRenderer; import kr.xit.framework.support.util.ValidationError; import kr.xit.framework.support.util.constants.MessageKey; import lombok.RequiredArgsConstructor; +import springfox.documentation.annotations.ApiIgnore; +@Api(value="코드 상세 관리", tags = "CodeDtlMgtController") @RequiredArgsConstructor @Controller @RequestMapping("/framework/biz/mng/code") public class CodeDtlMgtController { - + private final ICodeDtlMgtService service; + @ApiOperation(value = "코드 상세 관리 화면", hidden = true) @RequestMapping(value = "/mngCodeDtlMgtForm") public void mngCodeDtlMgtForm() { } - @RequestMapping(value = "/mngCodeDtlMgtPopup") - public ModelAndView mngCodeDtlMgtPopup(final XitDetailCodeMngVO vo) { + @ApiOperation(value = "코드 상세 관리 팝업 화면") + @ApiImplicitParam(name = "codeId", value = "코드 ID", required = true, dataType = "string", paramType = "path", defaultValue = "FIM001") + @RequestMapping(value = "/mngCodeDtlMgtPopup", method= {RequestMethod.GET, RequestMethod.POST}) + public ModelAndView mngCodeDtlMgtPopup(@ApiIgnore final XitDetailCodeMngVO vo) { ModelAndView mav = new ModelAndView(); mav.addObject("cfnCodeList", CacheServiceUtils.getComboCodes(null, "CMM_CFN")); @@ -55,7 +65,7 @@ public class CodeDtlMgtController { return ResultResponse.of(service.findCodeDtls(paraMap, MybatisUtils.getPagingInfo(paraMap))); } - @PostMapping(value = "/addCodeDtl") + @PostMapping(value = "/addCodeDtl") //, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public ModelAndView addCodeDtl(final XitDetailCodeMngVO vo, final BindingResult bindingResult){ ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW); diff --git a/src/main/java/kr/xit/framework/core/aop/LogAopAdvice.java b/src/main/java/kr/xit/framework/core/aop/LogAopAdvice.java index 4350f3cd..7bd7bc25 100644 --- a/src/main/java/kr/xit/framework/core/aop/LogAopAdvice.java +++ b/src/main/java/kr/xit/framework/core/aop/LogAopAdvice.java @@ -163,7 +163,7 @@ public class LogAopAdvice { do { pName = (String) e.nextElement(); pValue = request.getParameter(pName); - sb.append(pName + " : [" + pValue + "]\n"); + sb.append(pName + ": " + pValue + "\n"); } while (e.hasMoreElements()); } else { sb.append(" is Empty \n"); diff --git a/src/main/java/kr/xit/framework/core/config/Swagger2Config.java b/src/main/java/kr/xit/framework/core/config/Swagger2Config.java index 574c5f97..67358a39 100644 --- a/src/main/java/kr/xit/framework/core/config/Swagger2Config.java +++ b/src/main/java/kr/xit/framework/core/config/Swagger2Config.java @@ -1,6 +1,9 @@ package kr.xit.framework.core.config; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.springframework.context.annotation.Bean; @@ -10,39 +13,44 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.builders.ResponseMessageBuilder; import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.service.AuthorizationScope ; +import springfox.documentation.service.ResponseMessage; +import springfox.documentation.service.SecurityReference; import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger.web.DocExpansion; +import springfox.documentation.swagger.web.ModelRendering; +import springfox.documentation.swagger.web.OperationsSorter; +import springfox.documentation.swagger.web.TagsSorter; +import springfox.documentation.swagger.web.UiConfiguration; +import springfox.documentation.swagger.web.UiConfigurationBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 +//@EnableSwagger2WebMvc @EnableWebMvc public class Swagger2Config { - // @Bean - // public Docket api() { - // return new Docket(DocumentationType.SWAGGER_2) - // .apiInfo(apiInfo()) - // .select() - // //.apis(RequestHandlerSelectors.any()) - // .apis(RequestHandlerSelectors.basePackage("kr.xit.fims")) - // // .paths(PathSelectors.regex("/")) - // //.paths(PathSelectors.any()) - // .paths(PathSelectors.ant("/**")) - // .build(); - // } @Bean public Docket newsApiAll() { return new Docket(DocumentationType.SWAGGER_2) - .groupName("01. FIMS Biz API REST Service") .consumes(getConsumeContentTypes()) - .produces(getProduceContentTypes()) - .apiInfo(apiInfo()) + //.produces(getProduceContentTypes()) + .groupName("01. FIMS Biz API REST Service") .select() - .apis(RequestHandlerSelectors.basePackage("kr.xit.fims")) - .paths(PathSelectors.ant("/**")) - .build(); + .apis(RequestHandlerSelectors.basePackage("kr.xit.fims.biz")) + .paths(PathSelectors.ant("/fims/biz/**")) + .build() + .apiInfo(apiInfo()) + //.globalResponseMessage(RequestMethod.GET, getResMessages()) + //.securityContexts(Arrays.asList(securityContext())) + //.securitySchemes(Arrays.asList(apiKey())) + ; } @Bean @@ -50,14 +58,37 @@ public class Swagger2Config { return new Docket(DocumentationType.SWAGGER_2) .groupName("02. Framework Biz API REST Service") .consumes(getConsumeContentTypes()) - .produces(getProduceContentTypes()) - .apiInfo(apiInfo()) + //.produces(getProduceContentTypes()) .select() - .apis(RequestHandlerSelectors.basePackage("kr.xit.framework")) - .paths(PathSelectors.ant("/**")) - .build(); + .apis(RequestHandlerSelectors.basePackage("kr.xit.framework.biz")) + .paths(PathSelectors.ant("/framework/biz/**")) + .build() + .apiInfo(apiInfo()) + //.globalResponseMessage(RequestMethod.GET, getResMessages()) + //.securityContexts(Arrays.asList(securityContext())) + //.securitySchemes(Arrays.asList(apiKey())) + ; } + @Bean + public UiConfiguration uiConfig() { + return UiConfigurationBuilder.builder() + .deepLinking(false) + .displayOperationId(false) + .defaultModelsExpandDepth(-1) + .defaultModelExpandDepth(1) + .defaultModelRendering(ModelRendering.EXAMPLE) + .displayRequestDuration(false) + .docExpansion(DocExpansion.NONE) + .filter(false) + .maxDisplayedTags(null) + .operationsSorter(OperationsSorter.METHOD) + .showExtensions(false) + .tagsSorter(TagsSorter.ALPHA) + .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS) + .validatorUrl(null) + .build(); + } private ApiInfo apiInfo() { return new ApiInfoBuilder() @@ -70,10 +101,36 @@ public class Swagger2Config { .build(); } + private List getResMessages() { + List responseMessages = new ArrayList<>(); + responseMessages.add(new ResponseMessageBuilder() + .code(200) + .message("OK") + .build()); + responseMessages.add(new ResponseMessageBuilder() + .code(401) + .message("Unauthorized") + .build()); + responseMessages.add(new ResponseMessageBuilder() + .code(403) + .message("Forbidden") + .build()); + responseMessages.add(new ResponseMessageBuilder() + .code(404) + .message("Not Found") + .build()); + responseMessages.add(new ResponseMessageBuilder() + .code(500) + .message("Internal Server Error") + .build()); + + return responseMessages; + } + private Set getConsumeContentTypes() { Set consumes = new HashSet<>(); - consumes.add("application/json;charset=UTF-8"); consumes.add("application/x-www-form-urlencoded"); + consumes.add("application/json;charset=UTF-8"); return consumes; } @@ -82,4 +139,22 @@ public class Swagger2Config { produces.add("application/json;charset=UTF-8"); return produces; } + + //ApiKey 정의 + private ApiKey apiKey() { + //return new ApiKey("JWT", "Authorization", "header"); + return new ApiKey("Authorization", "Authorization", "header"); + } + + //JWT SecurityContext 구성 + private SecurityContext securityContext() { + return SecurityContext.builder().securityReferences(defaultAuth()).build(); + } + + private List defaultAuth() { + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEveryThing"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + return Arrays.asList(new SecurityReference("Authorization", authorizationScopes)); + } } diff --git a/src/main/resources/props/local/globals.properties b/src/main/resources/props/local/globals.properties index 35d6ed81..692534b6 100644 --- a/src/main/resources/props/local/globals.properties +++ b/src/main/resources/props/local/globals.properties @@ -155,3 +155,4 @@ file.snd.path=/Users/minuk/data/fims/SND # \uC678\uBD80\uC5F0\uACC4 URL app.extnl.car.url=http://211.119.124.9:18090 +springdoc.version=v1