聚合各个子系统的文档
This commit is contained in:
+7
-2
@@ -95,9 +95,14 @@
|
||||
<!--<artifactId>zipkin-autoconfigure-ui</artifactId>-->
|
||||
<!--<scope>runtime</scope>-->
|
||||
<!--</dependency>-->
|
||||
<!--引入swagger2文档依赖-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -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<SwaggerResource> 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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,3 +27,4 @@ ms:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user