燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-07-14 db44f336e46825afc855466512065cc08e5790bd
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
62
63
64
65
66
67
68
69
70
71
package com.yssh.config;
 
import io.swagger.annotations.ApiOperation;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
 
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
 
/**
 * @author wMeng
 * @ClassName SwaggerConfig
 * @Description TODO
 * @date 2022/10/31 18:55
 * @Version 1.0
 */
@Configuration
@EnableKnife4j
public class Knife4jConfig {
 
    @Value("${knife4j.enabled}")
    private boolean enabled;
 
    /**
     * 设置请求的统一前缀
     */
    @Value("${knife4j.pathMapping}")
    private String pathMapping;
 
    @Bean
    public Docket createRestApi() {
        return new Docket(new DocumentationType("openApi", "3.0"))
                // 是否启用Swagger
                .enable(enabled)
                // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
                .apiInfo(apiInfo())
                // 分组名称
                .groupName("服务")
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 扫描所有有注解的api,用这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                // 扫描指定包中的swagger注解
                // .apis(RequestHandlerSelectors.basePackage("com.cn.project.tool.swagger"))
                // 扫描所有 .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                /* 设置安全模式,swagger可以设置访问token */
                // .securitySchemes(securitySchemes())
                .pathMapping(pathMapping);
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //描述字段支持Markdown语法
                .description("我的接口测试文档")
                .contact(new Contact("张腾飞", "http://127.0.0.1:9001/doc.html", "893732661@qq.com"))
                .version("2.0.0")
                .title("燕山石化API接口测试文档")
                .build();
    }
}