Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add knife4j by a new module named linkis-knif4j #2366

Merged
merged 6 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions linkis-commons/linkis-knife4j/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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")
}
}
1 change: 1 addition & 0 deletions linkis-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>linkis-mybatis</module>
<module>linkis-rpc</module>
<module>linkis-storage</module>
<module>linkis-knife4j</module>
</modules>

</project>
13 changes: 13 additions & 0 deletions linkis-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 21 additions & 0 deletions tool/dependencies/known-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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