Skip to content

Commit

Permalink
增加knife4j 接口文档
Browse files Browse the repository at this point in the history
  • Loading branch information
song xiaolang committed Mar 25, 2022
1 parent 9568b97 commit 381e4c0
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 3 deletions.
7 changes: 7 additions & 0 deletions dataintegration-common/dataintegration-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,12 @@
<scope>provided</scope>
</dependency>

<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>

</dependencies>
</project>
7 changes: 7 additions & 0 deletions dataintegration-common/dataintegration-starter-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<artifactId>dataintegration-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!--servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.youngdatafan.dataintegration.core.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.RequestParameter;
import springfox.documentation.service.Response;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
* swagger自动配置.
*
* @author gavin
* @create 2020/8/21 4:39 下午
*/
@ConditionalOnClass(value = EnableOpenApi.class)
@EnableOpenApi
@EnableKnife4j
@Configuration
@Import(SwaggerHeaderTransformationFilter.class)
public class SwaggerConfiguration {

/**
* 创建Docket.
*
* @return Docket
*/
@Bean
public Docket createRestApi() {
//返回文档摘要信息
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.globalRequestParameters(getGlobalRequestParameters())
.globalResponses(HttpMethod.GET, getGlobalResponseMessage())
.globalResponses(HttpMethod.POST, getGlobalResponseMessage());
}

/**
* 生成接口信息,包括标题、联系人等.
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口文档")
.description("")
.contact(new Contact("stella", "senses-ai", "[email protected]"))
.version("1.0")
.build();
}

/**
* 生成全局通用参数.
*/
private List<RequestParameter> getGlobalRequestParameters() {
return Collections.emptyList();
}

/**
* 生成通用响应信息.
*/
private List<Response> getGlobalResponseMessage() {
List<Response> responseList = new ArrayList<>();
responseList.add(new ResponseBuilder().code("404").description("找不到资源").build());
return responseList;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.youngdatafan.dataintegration.core.config;

import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.swagger2.web.SwaggerTransformationContext;
import springfox.documentation.swagger2.web.WebMvcSwaggerTransformationFilter;

/**
* swagger header自定义处理过滤器.
* @author gavin
* @create 2022/2/9 21:06
*/
@Component
public class SwaggerHeaderTransformationFilter implements WebMvcSwaggerTransformationFilter {

private static final String HEADER_NAME = "X-Forwarded-Prefix";

@Override
public Swagger transform(SwaggerTransformationContext<HttpServletRequest> context) {
HttpServletRequest request = context.request().get();

final String basePath = request.getHeader(HEADER_NAME);
if (basePath == null || !basePath.startsWith("/api")) {
// 如果没有HEADER_NAME请求头,并且不是/api开头,则代表不是通过网关访问,就不需要设置header
return context.getSpecification();
}

Swagger swagger = context.getSpecification();
swagger.setBasePath(basePath);

swagger.getPaths().forEach((s, pathItem) -> {
for (Operation readOperation : pathItem.getOperations()) {
final List<Parameter> parameters = readOperation.getParameters();
if (parameters == null) {
continue;
}

List<Parameter> newParameters = new ArrayList<>();
for (Parameter parameter : parameters) {
if (!parameter.getIn().equalsIgnoreCase("header")) {
newParameters.add(parameter);
}
}
readOperation.setParameters(newParameters);
}
});

return swagger;
}

@Override
public boolean supports(DocumentationType documentationType) {
return documentationType.equals(DocumentationType.SWAGGER_2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<openoffice.version>4.2.2</openoffice.version>
<poi.version>3.17</poi.version>
<mysql.version>5.1.47</mysql.version>
<swagger2.version>3.0.0</swagger2.version>
</properties>
<dependencies>

Expand Down Expand Up @@ -81,10 +82,11 @@
</dependency>

<!-- swagger-ui -->
<!-- <dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>-->
<version>${swagger2.version}</version>
</dependency>

<dependency>
<groupId>com.auth0</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
server:
port: 10210

spring:
cloud:
consul:
host: 192.168.10.160
port: 8500
discovery:
service-name: ${spring.application.name}
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.10.211:13306/dataintegration?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: stelladp
password: 123456
hikari:
minimum-idle: 1
maximum-pool-size: 10
max-lifetime: 1800000
idle-timeout: 600000
connection-timeout: 30000
connection-test-query: SELECT 1
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
servlet:
multipart:
max-file-size: 1GB
max-request-size: 1GB
redis:
host: 192.168.10.211
port: 39121
password:
lettuce:
shutdown-timeout: 100 # 关闭超时时间
pool:
max-active: 100 # 连接池最大连接数(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
max-wait: 1000 # 连接池最大阻塞等待时间(使用负值表示没有限制)
min-idle: 1 # 连接池中的最小空闲连接
cache:
type: redis

#配置MyBatis
mybatis:
mapper-locations: classpath*:com/youngdatafan/dataintegration/file/management/mapping/*Mapper.xml
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl

#pagehelper
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql

#ftp:
# server: 127.0.0.1
# port: 20021
# userName: prime
# password: prime@2020
# passiveMode: true
# ftpEncoding: utf-8
#10.242.10.170:30021


#文件存储类型
file:
server:
useServer: s3
ftp:
server: 192.168.124.166
port: 20021
userName: prime
password: prime@2020
passiveMode: true
ftpEncoding: utf-8
rootPath: ftp://
createDir: true
s3:
server: 192.168.10.211
port: 8080
userName: BMXG3WP8JA9D1GSD2AJJ
password: vl32x2t0sBxy0BEgcY9Iz442HK2HobPTNw4T99yK
rootPath: s3://
bucket: escat-s3
createDir: true


logging:
file:
# 配置日志目录,logbak.xml使用
path: ./logs/${spring.application.name}
# springboot admin获取日志使用
name: ${logging.file.path}/all/${spring.application.name}.log

##################################################
# JodConverter Configuration

jodconverter:
local:
enabled: true
office-home: /Applications/OpenOffice.app/Contents/
max-tasks-per-process: 10
port-numbers: 8123
7 changes: 7 additions & 0 deletions dataintegration-group/dataintegration-group-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.3</version>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
<optional>true</optional>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@
<scope>test</scope>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 7 additions & 0 deletions dataintegration-sso/dataintegration-sso-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger2.version}</version>
</dependency>
</dependencies>


Expand Down
Loading

0 comments on commit 381e4c0

Please sign in to comment.