mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
fix: openapi can't work in springboot 2.7.4 #559
This commit is contained in:
parent
5985c04997
commit
d45cb0712c
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<swagger.version>2.9.2</swagger.version>
|
|
||||||
<springboot.version>2.7.4</springboot.version>
|
<springboot.version>2.7.4</springboot.version>
|
||||||
|
|
||||||
<!-- MySQL version that corresponds to spring-boot-dependencies version. -->
|
<!-- MySQL version that corresponds to spring-boot-dependencies version. -->
|
||||||
@ -53,6 +52,7 @@
|
|||||||
<powerjob-common.version>4.3.0</powerjob-common.version>
|
<powerjob-common.version>4.3.0</powerjob-common.version>
|
||||||
<powerjob-remote-impl-http.version>4.3.0</powerjob-remote-impl-http.version>
|
<powerjob-remote-impl-http.version>4.3.0</powerjob-remote-impl-http.version>
|
||||||
<powerjob-remote-impl-akka.version>4.3.0</powerjob-remote-impl-akka.version>
|
<powerjob-remote-impl-akka.version>4.3.0</powerjob-remote-impl-akka.version>
|
||||||
|
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -264,25 +264,14 @@
|
|||||||
<version>${cron-utils.version}</version>
|
<version>${cron-utils.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- swagger2 -->
|
<!-- OPEN API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>${swagger.version}</version>
|
<version>${springdoc-openapi-ui.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<!-- swagger2 ui -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-jsr223 -->
|
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-jsr223 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
@ -1,30 +1,29 @@
|
|||||||
package tech.powerjob.server.config;
|
package tech.powerjob.server.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.info.License;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
import tech.powerjob.server.common.PowerJobServerConfigKey;
|
import tech.powerjob.server.common.PowerJobServerConfigKey;
|
||||||
import tech.powerjob.server.remote.server.self.ServerInfoService;
|
import tech.powerjob.server.remote.server.self.ServerInfoService;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import static springfox.documentation.builders.PathSelectors.any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration class for Swagger UI.
|
* Configuration class for Swagger UI.
|
||||||
|
* migrate to <a href="https://springdoc.org/">springdoc</a> from v4.3.1
|
||||||
|
* <a href="http://localhost:7700/swagger-ui/index.html#/">api address</a>
|
||||||
*
|
*
|
||||||
* @author tjq
|
* @author tjq
|
||||||
* @author Jiang Jining
|
* @author Jiang Jining
|
||||||
* @since 2020/3/29
|
* @since 2020/3/29
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableSwagger2
|
|
||||||
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
|
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SwaggerConfig {
|
public class SwaggerConfig {
|
||||||
@ -32,24 +31,28 @@ public class SwaggerConfig {
|
|||||||
private final ServerInfoService serverInfoService;
|
private final ServerInfoService serverInfoService;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket createRestApi() {
|
public OpenAPI springShopOpenAPI() {
|
||||||
|
|
||||||
// apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
|
// apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
|
||||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
return new OpenAPI()
|
||||||
.title("PowerJob")
|
.info(new Info().title("PowerJob")
|
||||||
.description("Distributed scheduling and computing framework.")
|
.description("Distributed scheduling and computing framework.")
|
||||||
.license("Apache Licence 2")
|
|
||||||
.termsOfServiceUrl("https://github.com/PowerJob/PowerJob")
|
|
||||||
.version(serverInfoService.fetchServiceInfo().getVersion())
|
.version(serverInfoService.fetchServiceInfo().getVersion())
|
||||||
|
.license(new License().name("Apache License 2.0").url("https://github.com/PowerJob/PowerJob/blob/master/LICENSE")))
|
||||||
|
.externalDocs(new ExternalDocumentation()
|
||||||
|
.description("Distributed scheduling and computing framework.")
|
||||||
|
.url("http://www.powerjob.tech/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi createRestApi() {
|
||||||
|
|
||||||
|
log.warn("[OpenAPI] openapi has been activated, make sure you want to enable it!");
|
||||||
|
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("PowerJob-ALL")
|
||||||
|
.pathsToMatch("/**")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo)
|
|
||||||
// select()函数返回一个ApiSelectorBuilder实例
|
|
||||||
.select()
|
|
||||||
// 决定了暴露哪些接口给 Swagger
|
|
||||||
.paths(any())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user