From 5d0225f25dd6c6476e7f648bf2cf84ff58872f10 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Wed, 9 May 2018 07:47:10 +0800 Subject: [PATCH] =?UTF-8?q?update[litemall-core]:=20=E6=94=AF=E6=8C=81swag?= =?UTF-8?q?ger2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../litemall/core/config/SwaggerConfig.java | 43 +++++++++++++++++++ .../main/resources/application-dep.properties | 1 + .../main/resources/application-dev.properties | 1 + .../resources/application-prod.properties | 1 + .../src/main/resources/application.properties | 1 + 5 files changed, 47 insertions(+) create mode 100644 litemall-core/src/main/java/org/linlinjava/litemall/core/config/SwaggerConfig.java create mode 100644 litemall-core/src/main/resources/application-dep.properties create mode 100644 litemall-core/src/main/resources/application-dev.properties create mode 100644 litemall-core/src/main/resources/application-prod.properties create mode 100644 litemall-core/src/main/resources/application.properties diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/SwaggerConfig.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/SwaggerConfig.java new file mode 100644 index 00000000..da953434 --- /dev/null +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/SwaggerConfig.java @@ -0,0 +1,43 @@ +package org.linlinjava.litemall.core.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + @Value("${swagger.enable:true}") + private boolean enableSwagger; + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .enable(enableSwagger) + .select() + .apis(RequestHandlerSelectors.basePackage("org.linlinjava.litemall")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("litemall") + .description("又一个小商城。litemall = Spring Boot后端 + Vue管理员前端 + 微信小程序用户前端") + .termsOfServiceUrl("https://github.com/linlinjava/litemall") + .version("0.1.0") + .license("MIT") + .licenseUrl("https://github.com/linlinjava/litemall/blob/master/LICENSE") + .contact(new Contact("linlinjava", "https://github.com/linlinjava", "linlinjava@163.com")) + .build(); + } +} diff --git a/litemall-core/src/main/resources/application-dep.properties b/litemall-core/src/main/resources/application-dep.properties new file mode 100644 index 00000000..e4f4c24d --- /dev/null +++ b/litemall-core/src/main/resources/application-dep.properties @@ -0,0 +1 @@ +swagger.enable=true \ No newline at end of file diff --git a/litemall-core/src/main/resources/application-dev.properties b/litemall-core/src/main/resources/application-dev.properties new file mode 100644 index 00000000..e4f4c24d --- /dev/null +++ b/litemall-core/src/main/resources/application-dev.properties @@ -0,0 +1 @@ +swagger.enable=true \ No newline at end of file diff --git a/litemall-core/src/main/resources/application-prod.properties b/litemall-core/src/main/resources/application-prod.properties new file mode 100644 index 00000000..fc0d59bd --- /dev/null +++ b/litemall-core/src/main/resources/application-prod.properties @@ -0,0 +1 @@ +swagger.enable=false \ No newline at end of file diff --git a/litemall-core/src/main/resources/application.properties b/litemall-core/src/main/resources/application.properties new file mode 100644 index 00000000..257b3064 --- /dev/null +++ b/litemall-core/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.profiles.active=dev \ No newline at end of file