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>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
<springboot.version>2.7.4</springboot.version>
|
||||
|
||||
<!-- MySQL version that corresponds to spring-boot-dependencies version. -->
|
||||
@ -53,6 +52,7 @@
|
||||
<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-akka.version>4.3.0</powerjob-remote-impl-akka.version>
|
||||
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -264,25 +264,14 @@
|
||||
<version>${cron-utils.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<!-- OPEN API -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.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>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>${springdoc-openapi-ui.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-jsr223 -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
|
@ -1,55 +1,58 @@
|
||||
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.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.GroupedOpenApi;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.remote.server.self.ServerInfoService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static springfox.documentation.builders.PathSelectors.any;
|
||||
|
||||
/**
|
||||
* 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 Jiang Jining
|
||||
* @since 2020/3/29
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
|
||||
@RequiredArgsConstructor
|
||||
public class SwaggerConfig {
|
||||
|
||||
private final ServerInfoService serverInfoService;
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
|
||||
@Bean
|
||||
public OpenAPI springShopOpenAPI() {
|
||||
// apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("PowerJob")
|
||||
.description("Distributed scheduling and computing framework.")
|
||||
.license("Apache Licence 2")
|
||||
.termsOfServiceUrl("https://github.com/PowerJob/PowerJob")
|
||||
.version(serverInfoService.fetchServiceInfo().getVersion())
|
||||
.build();
|
||||
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo)
|
||||
// select()函数返回一个ApiSelectorBuilder实例
|
||||
.select()
|
||||
// 决定了暴露哪些接口给 Swagger
|
||||
.paths(any())
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("PowerJob")
|
||||
.description("Distributed scheduling and computing framework.")
|
||||
.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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user