WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tech.powerjob.server.config;
 
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
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 tech.powerjob.server.common.PowerJobServerConfigKey;
import tech.powerjob.server.remote.server.self.ServerInfoService;
 
/**
 * 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
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
@RequiredArgsConstructor
public class SwaggerConfig {
    
    private final ServerInfoService serverInfoService;
 
    @Bean
    public OpenAPI springShopOpenAPI() {
        final Contact contact = new Contact();
        contact.setName("Team PowerJob");
        contact.setUrl("http://www.powerjob.tech");
        contact.setEmail("tengjiqi@gmail.com");
 
        // apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
        return new OpenAPI()
                .info(new Info().title("PowerJob")
                        .description("Distributed scheduling and computing framework.")
                        .version(serverInfoService.fetchCurrentServerInfo().getVersion())
                        .contact(contact)
                        .license(new License().name("Apache License 2.0").url("https://github.com/PowerJob/PowerJob/blob/master/LICENSE")));
    }
 
    @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();
 
    }
    
}