# 接口文档配置

默认使用Knife4j (opens new window)实现Swagger2配置

# Yaml配置

下列为可选配置,默认自带配置请参考application-knife4j.yml (opens new window)

# ========================= Knife4j Setting =========================
knife4j:
  setting:
    # 是否启动自定义Host配置
    enableHost: false
    # Host地址/端口
    enableHostText:
    # 是否开启分组
    enableGroup: true
  basic:
    # 是否打开BasicHttp验证
    enable: false
    # Basic登录用户名
    username:
    # Basic登录密码
    password:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# SwaggerFactory (opens new window)

该类为swagger工厂类,由它来创建Docket对象

# SwaggerInfo (opens new window)

该类为Swagger配置信息,可动态修改Swagger相关信息

# 配置示例

# 简单配置

@SpringBootConfiguration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Resource
    private OpenApiExtensionResolver openApiExtensionResolver;

    @Bean
    public Docket createAppRestApi() {
        return SwaggerFactory.createRestApi(SwaggerInfo.builder()
                .basePackage("pro.haichuang.framework.service.项目Code.xx")
                .openApiExtensionResolver(openApiExtensionResolver)
                .parameters(Collections.singletonList(new ApiKey("[参数说明(Token)]", "[参数名(Authorization)]", "[参数位置(header|query)]")))
                .build());
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 分组配置

@SpringBootConfiguration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Resource
    private OpenApiExtensionResolver openApiExtensionResolver;

    @Bean
    public Docket createAppRestApi() {
        return SwaggerFactory.createRestApi(SwaggerInfo.builder()
                .groupName("APP")
                .basePackage("pro.haichuang.framework.service.项目Code.xx")
                .openApiExtensionResolver(openApiExtensionResolver)
                .parameters(Collections.singletonList(new ApiKey("[参数说明(Token)]", "[参数名(Authorization)]", "[参数位置(header|query)]")))
                .build());
    }

    @Bean
    public Docket createAppRestApi() {
        return SwaggerFactory.createRestApi(SwaggerInfo.builder()
                .groupName("CMS")
                .basePackage("pro.haichuang.framework.service.项目Code.xx")
                .openApiExtensionResolver(openApiExtensionResolver)
                .parameters(Collections.singletonList(new ApiKey("[参数说明(Token)]", "[参数名(Authorization)]", "[参数位置(header|query)]")))
                .build());
    }
}
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
Last Updated: 12/14/2021, 5:11:19 PM