燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-13 2f55cebbad3dea187a5f91d16ec80a9677dab699
src/main/java/com/yssh/config/Knife4jConfig.java
@@ -16,55 +16,44 @@
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}")
    @Value("${knife4j.enabled}")
    private boolean enabled;
    /** 设置请求的统一前缀 */
    @Value("${knife4j.pathMapping}")
    private String pathMapping;
    @Bean
    public Docket createRestApi() {
       return new Docket(DocumentationType.OAS_30)
        // 是否启用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);
        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:8099/doc.html", "893732661@qq.com"))
              .version("2.0.0")
                .description("我的接口测试文档")
                .contact(new Contact("张腾飞", "http://127.0.0.1:9001/doc.html", "893732661@qq.com"))
                .version("2.0.0")
                .title("燕山石化API接口测试文档")
                .build();
    }