From 705663da49a042d407492ca8f774d6ccf326dd07 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Tue, 18 Apr 2023 12:41:36 +0900 Subject: [PATCH] feat: swagger2 set --- pom.xml | 15 ++++ .../framework/core/config/Swagger2Config.java | 85 +++++++++++++++++++ src/main/resources/spring/context-mvc.xml | 1 + .../resources/spring/mvc/mvc-swagger2.xml | 11 +++ .../spring/service/context-security.xml | 13 +++ src/main/webapp/WEB-INF/web.xml | 7 ++ 6 files changed, 132 insertions(+) create mode 100644 src/main/java/kr/xit/framework/core/config/Swagger2Config.java create mode 100644 src/main/resources/spring/mvc/mvc-swagger2.xml diff --git a/pom.xml b/pom.xml index ef8ba247..8ef7ec2e 100644 --- a/pom.xml +++ b/pom.xml @@ -208,6 +208,21 @@ + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + org.thymeleaf thymeleaf diff --git a/src/main/java/kr/xit/framework/core/config/Swagger2Config.java b/src/main/java/kr/xit/framework/core/config/Swagger2Config.java new file mode 100644 index 00000000..574c5f97 --- /dev/null +++ b/src/main/java/kr/xit/framework/core/config/Swagger2Config.java @@ -0,0 +1,85 @@ +package kr.xit.framework.core.config; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +@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()) + .select() + .apis(RequestHandlerSelectors.basePackage("kr.xit.fims")) + .paths(PathSelectors.ant("/**")) + .build(); + } + + @Bean + public Docket newsApiAccelerator() { + return new Docket(DocumentationType.SWAGGER_2) + .groupName("02. Framework Biz API REST Service") + .consumes(getConsumeContentTypes()) + .produces(getProduceContentTypes()) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("kr.xit.framework")) + .paths(PathSelectors.ant("/**")) + .build(); + } + + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("통합플랫폼 Rest API Documentation") + .description("통합플랫폼 Rest api 서비스") + .termsOfServiceUrl("https://www.egovframe.go.kr/wiki/doku.php?id=egovframework:hyb:gate_page") + .license("Apache License Version 2.0") + .licenseUrl("https://www.egovframe.go.kr") + .version("0.1") + .build(); + } + + private Set getConsumeContentTypes() { + Set consumes = new HashSet<>(); + consumes.add("application/json;charset=UTF-8"); + consumes.add("application/x-www-form-urlencoded"); + return consumes; + } + + private Set getProduceContentTypes() { + Set produces = new HashSet<>(); + produces.add("application/json;charset=UTF-8"); + return produces; + } +} diff --git a/src/main/resources/spring/context-mvc.xml b/src/main/resources/spring/context-mvc.xml index d4d1ce42..02057e8f 100644 --- a/src/main/resources/spring/context-mvc.xml +++ b/src/main/resources/spring/context-mvc.xml @@ -29,6 +29,7 @@ + diff --git a/src/main/resources/spring/mvc/mvc-swagger2.xml b/src/main/resources/spring/mvc/mvc-swagger2.xml new file mode 100644 index 00000000..978fe140 --- /dev/null +++ b/src/main/resources/spring/mvc/mvc-swagger2.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/src/main/resources/spring/service/context-security.xml b/src/main/resources/spring/service/context-security.xml index 0a74e504..b58eb129 100644 --- a/src/main/resources/spring/service/context-security.xml +++ b/src/main/resources/spring/service/context-security.xml @@ -20,6 +20,19 @@ + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index f05f759a..5e56071e 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -121,6 +121,13 @@ action *.do *.ajax + + + /swagger-ui.html + /webjars/** + / + +