From 05cc87ce097f16b8e9694ebfb9e21aebd969a3db Mon Sep 17 00:00:00 2001
From: lsy <18332763730@163.com>
Date: Mon, 25 Dec 2017 23:06:21 +0800
Subject: [PATCH] =?UTF-8?q?=E8=81=9A=E5=90=88=E5=90=84=E4=B8=AA=E5=AD=90?=
=?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=9A=84=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ms/gateway/pom.xml | 9 ++-
.../gateway/config/DocumentationConfig.java | 40 +++++++++++++
.../fast/gateway/config/SwaggerUiConfig.java | 56 +++++++++++++++++++
ms/gateway/src/main/resources/bootstrap.yml | 6 ++
ms/upms/src/main/resources/bootstrap.yml | 1 +
5 files changed, 110 insertions(+), 2 deletions(-)
create mode 100644 ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java
create mode 100644 ms/gateway/src/main/java/com/micro/fast/gateway/config/SwaggerUiConfig.java
diff --git a/ms/gateway/pom.xml b/ms/gateway/pom.xml
index 0b91dd0..2c99528 100644
--- a/ms/gateway/pom.xml
+++ b/ms/gateway/pom.xml
@@ -95,9 +95,14 @@
+
- org.projectlombok
- lombok
+ io.springfox
+ springfox-swagger2
+
+
+ io.springfox
+ springfox-swagger-ui
diff --git a/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java b/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java
new file mode 100644
index 0000000..7533326
--- /dev/null
+++ b/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java
@@ -0,0 +1,40 @@
+package com.micro.fast.gateway.config;
+
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+import springfox.documentation.swagger.web.SwaggerResource;
+import springfox.documentation.swagger.web.SwaggerResourcesProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author lsy
+ * 聚合各个子系统的文档
+ */
+@Component
+@Primary
+public class DocumentationConfig implements SwaggerResourcesProvider {
+ @Override
+ public List get() {
+ List resources = new ArrayList<>();
+ resources.add(swaggerResource("订单系统", "/order/v2/api-docs", "2.0"));
+ resources.add(swaggerResource("支付系统", "/pay/v2/api-docs", "2.0"));
+ return resources;
+ }
+
+ /**
+ * 添加要聚合的子系统swagger资源对象
+ * @param name 子系统文档的名称
+ * @param location 聚合子系统swagger的文档api路径
+ * @param version swagger的版本
+ * @return
+ */
+ private SwaggerResource swaggerResource(String name, String location, String version) {
+ SwaggerResource swaggerResource = new SwaggerResource();
+ swaggerResource.setName(name);
+ swaggerResource.setLocation(location);
+ swaggerResource.setSwaggerVersion(version);
+ return swaggerResource;
+ }
+}
diff --git a/ms/gateway/src/main/java/com/micro/fast/gateway/config/SwaggerUiConfig.java b/ms/gateway/src/main/java/com/micro/fast/gateway/config/SwaggerUiConfig.java
new file mode 100644
index 0000000..6cd76f4
--- /dev/null
+++ b/ms/gateway/src/main/java/com/micro/fast/gateway/config/SwaggerUiConfig.java
@@ -0,0 +1,56 @@
+package com.micro.fast.gateway.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.context.request.async.DeferredResult;
+import springfox.documentation.builders.ApiInfoBuilder;
+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;
+
+import static com.google.common.base.Predicates.or;
+import static springfox.documentation.builders.PathSelectors.regex;
+
+/**
+ * @author lsy
+ * swagger文档生成配置
+ */
+@Configuration
+@EnableSwagger2
+public class SwaggerUiConfig {
+ @Bean
+ public Docket testApi() {
+ return new Docket(DocumentationType.SPRING_WEB)
+ .groupName("portalUser")
+ .genericModelSubstitutes(DeferredResult.class)
+ //.genericModelSubstitutes(ResponseEntity.class)
+ .useDefaultResponseMessages(false)
+ .forCodeGeneration(true)
+ // base,最终调用接口后会和paths拼接在一起
+ .pathMapping("/")
+ .select()
+ //需要进行写入文档的接口
+ .paths(or(regex("/tesco/user/.*")))
+ .build()
+ .apiInfo(portalUserApiInfo());
+ }
+
+ private ApiInfo portalUserApiInfo() {
+ return new ApiInfoBuilder()
+ //大标题
+ .title("MS系统文档")
+ //详细描述
+ .description("系统接口说明")
+ //版本
+ .version("0.0.1-SNAPSHOT")
+ .termsOfServiceUrl("NO terms of service")
+ //作者
+ .contact(new Contact("李守余", "http://kklt1996.gitee.io/blog/", "18332763730@163.com"))
+ .license("The Apache License, Version 2.0")
+ .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
+ .build();
+ }
+
+}
diff --git a/ms/gateway/src/main/resources/bootstrap.yml b/ms/gateway/src/main/resources/bootstrap.yml
index f15da69..5888fe6 100644
--- a/ms/gateway/src/main/resources/bootstrap.yml
+++ b/ms/gateway/src/main/resources/bootstrap.yml
@@ -16,6 +16,12 @@ eureka:
defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心
instance:
hostname: fthipw.natappfree.cc
+springfox:
+ documentation:
+ swagger:
+ v2:
+ path: /api/api-doc
+
diff --git a/ms/upms/src/main/resources/bootstrap.yml b/ms/upms/src/main/resources/bootstrap.yml
index 26a01ad..e791fcb 100644
--- a/ms/upms/src/main/resources/bootstrap.yml
+++ b/ms/upms/src/main/resources/bootstrap.yml
@@ -27,3 +27,4 @@ ms:
+