You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/07/04 13:50:31 UTC

[incubator-linkis] branch dev-1.2.0 updated: Add knife4j by a new module named linkis-knif4j (#2366)

This is an automated email from the ASF dual-hosted git repository.

casion pushed a commit to branch dev-1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.2.0 by this push:
     new b4627300e Add knife4j by a new module named linkis-knif4j (#2366)
b4627300e is described below

commit b4627300e2dc80ff3031a5d8140cb34c26941cba
Author: fanwenxiang <36...@users.noreply.github.com>
AuthorDate: Mon Jul 4 21:50:26 2022 +0800

    Add knife4j by a new module named linkis-knif4j (#2366)
    
    * Add knife4j by a new module named linkis-knif4j
    * Add jar to  known-dependencies.txt
---
 linkis-commons/linkis-knife4j/pom.xml              | 68 ++++++++++++++++
 .../knife4j/conf/Knife4jConfig/Knife4jConfig.scala | 91 ++++++++++++++++++++++
 linkis-commons/pom.xml                             |  1 +
 linkis-dist/pom.xml                                | 13 ++++
 pom.xml                                            |  2 +
 tool/dependencies/known-dependencies.txt           | 21 +++++
 6 files changed, 196 insertions(+)

diff --git a/linkis-commons/linkis-knife4j/pom.xml b/linkis-commons/linkis-knife4j/pom.xml
new file mode 100644
index 000000000..a993c6555
--- /dev/null
+++ b/linkis-commons/linkis-knife4j/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>linkis</artifactId>
+        <groupId>org.apache.linkis</groupId>
+        <version>1.1.3</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>linkis-knife4j</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <!--add knif2 dependency-->
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-spring-boot-starter</artifactId>
+            <version>${knife4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-webmvc</artifactId>
+            <version>${spring.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+        <finalName>${project.artifactId}-${project.version}</finalName>
+    </build>
+</project>
\ No newline at end of file
diff --git a/linkis-commons/linkis-knife4j/src/main/scala/org/apache/linkis/knife4j/conf/Knife4jConfig/Knife4jConfig.scala b/linkis-commons/linkis-knife4j/src/main/scala/org/apache/linkis/knife4j/conf/Knife4jConfig/Knife4jConfig.scala
new file mode 100644
index 000000000..554f5c6c3
--- /dev/null
+++ b/linkis-commons/linkis-knife4j/src/main/scala/org/apache/linkis/knife4j/conf/Knife4jConfig/Knife4jConfig.scala
@@ -0,0 +1,91 @@
+package org.apache.linkis.knife4j.conf.Knife4jConfig
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.springframework.context.annotation.Bean
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+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.EnableSwagger2WebMvc
+import org.springframework.beans.factory.annotation.Value
+
+/**
+ * it is very easy to enable knife when you want to use apiDoc(based on swagger2)
+ * you can follow these steps to enable
+ * 1, open application-linkis.yml and set knife4j.production=false
+ * 2, open linkis.properties and set wds.linkis.test.mode=true ## it will be renamed as linkis.test.mode in future release
+ * 3, restart the service and you can visit http://ip:port/api/rest_j/v1/doc.html
+ *
+ * or you can use apidoc by following steps  without enable wds.linkis.test.mode
+ * 1, open application-linkis.yml and set knife4j.production=false
+ * 2, open linkis.propertes ,and set wds.linkis.server.user.restful.uri.pass.auth=/api/rest_j/v1/doc.html,/api/rest_j/v1/swagger-resources,/api/rest_j/v1/webjars,/api/rest_j/v1/v2/api-docs
+ * 3, restart the service and you can visit http://ip:port/api/rest_j/v1/doc.html
+ * 4, in your browser,add dataworkcloud_inner_request=true, bdp-user-ticket-id's value and  workspaceId's value into cookie
+ */
+@EnableSwagger2WebMvc
+@EnableKnife4j
+@Configuration
+class Knife4jConfig extends WebMvcConfigurer {
+
+  @Value("${spring.application.name}") private val appName = "linkis service"
+
+  @Bean(Array("defaultApi2"))
+  def  defaultApi2() : Docket = {
+    val docket = new Docket(DocumentationType.SWAGGER_2)
+      .apiInfo(apiInfo())
+      //分组名称
+      .groupName("RESTAPI")
+      .select()
+      //这里指定Controller扫描包路径
+      .apis(RequestHandlerSelectors.basePackage("org.apache.linkis"))
+      .paths(PathSelectors.any())
+      .build()
+    docket
+  }
+
+  def  apiInfo() : ApiInfo ={
+    val apiInfo = new ApiInfoBuilder()
+      .title(appName)
+      .description("Linkis micro service RESTful APIs")
+      .version("v1")
+      .build()
+    apiInfo
+  }
+
+  override def addResourceHandlers( registry : ResourceHandlerRegistry): Unit  =  {
+    registry.addResourceHandler("/api/rest_j/v1/doc.html**").addResourceLocations("classpath:/META-INF/resources/doc.html")
+    registry.addResourceHandler("/api/rest_j/v1/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/")
+  }
+
+  override def addViewControllers(registry : ViewControllerRegistry ) : Unit = {
+    registry.addRedirectViewController("/api/rest_j/v1/v2/api-docs", "/v2/api-docs")
+    registry.addRedirectViewController("/api/rest_j/v1/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui")
+    registry.addRedirectViewController("/api/rest_j/v1/swagger-resources/configuration/security", "/swagger-resources/configuration/security")
+    registry.addRedirectViewController("/api/rest_j/v1/swagger-resources", "/swagger-resources")
+  }
+}
\ No newline at end of file
diff --git a/linkis-commons/pom.xml b/linkis-commons/pom.xml
index 23afc9f7f..4b515ada2 100644
--- a/linkis-commons/pom.xml
+++ b/linkis-commons/pom.xml
@@ -38,6 +38,7 @@
         <module>linkis-mybatis</module>
         <module>linkis-rpc</module>
         <module>linkis-storage</module>
+        <module>linkis-knife4j</module>
     </modules>
 
 </project>
\ No newline at end of file
diff --git a/linkis-dist/pom.xml b/linkis-dist/pom.xml
index 9efe7740f..81039bc19 100644
--- a/linkis-dist/pom.xml
+++ b/linkis-dist/pom.xml
@@ -153,6 +153,19 @@
             <version>1.9.4</version>
         </dependency>
 
+        <!--add knif4j-->
+        <dependency>
+            <groupId>org.apache.linkis</groupId>
+            <artifactId>linkis-knife4j</artifactId>
+            <version>${linkis.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-webmvc</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git a/pom.xml b/pom.xml
index 112f9147f..91e851de7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,6 +156,8 @@
         <maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
         <jacoco.version>0.8.7</jacoco.version>
         <jacoco.skip>false</jacoco.skip>
+        <spring.version>5.2.15.RELEASE</spring.version>
+        <knife4j.version>2.0.9</knife4j.version>
     </properties>
 
     <dependencyManagement>
diff --git a/tool/dependencies/known-dependencies.txt b/tool/dependencies/known-dependencies.txt
index 673c5b8c5..e7494707f 100644
--- a/tool/dependencies/known-dependencies.txt
+++ b/tool/dependencies/known-dependencies.txt
@@ -527,3 +527,24 @@ zookeeper-3.5.9.jar
 zookeeper-jute-3.5.9.jar
 zstd-jni-1.4.4-7.jar
 zstd-jni-1.4.5-6.jar
+byte-buddy-1.10.22.jar
+classgraph-4.1.7.jar
+knife4j-annotations-2.0.9.jar
+knife4j-core-2.0.9.jar
+knife4j-spring-2.0.9.jar
+knife4j-spring-boot-autoconfigure-2.0.9.jar
+knife4j-spring-boot-starter-2.0.9.jar
+knife4j-spring-ui-2.0.9.jar
+mapstruct-1.3.1.Final.jar
+spring-plugin-core-2.0.0.RELEASE.jar
+spring-plugin-metadata-2.0.0.RELEASE.jar
+springfox-bean-validators-2.10.5.jar
+springfox-core-2.10.5.jar
+springfox-schema-2.10.5.jar
+springfox-spi-2.10.5.jar
+springfox-spring-web-2.10.5.jar
+springfox-spring-webmvc-2.10.5.jar
+springfox-swagger-common-2.10.5.jar
+springfox-swagger2-2.10.5.jar
+swagger-annotations-1.5.22.jar
+swagger-models-1.5.22.jar


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org