Spring Boot中级篇-集成Swagger2分组文档

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012869196/article/details/83897772

Swagger配置文件
这里配置两个分组admin【后台管理接口】、wechat【微信管理接口】

@Configuration
@EnableSwagger2
public class Swagger2 {

    public static final String SWAGGER_SCAN_ADMIN_PACKAGE = "com.jacksony.module.admin.controller";
    public static final String ADMIN_VERSION = "1.0.0";
    public static final String SWAGGER_SCAN_WX_PACKAGE = "com.jacksony.module.wechat.controller";
    public static final String WX_VERSION = "1.0.0";

    @Bean
    public Docket createAdminRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台管理接口")
                .apiInfo(apiAdminInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_ADMIN_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/admin/.*"))//可以根据url路径设置哪些请求加入文档,忽略哪些请求
                .build();
    }
    private ApiInfo apiAdminInfo() {
        return new ApiInfoBuilder()
                .title("后台管理接口")//设置文档的标题
                .description("后台数据管理")//设置文档的描述->1.Overview
                .version(ADMIN_VERSION)//设置文档的版本信息-> 1.1 Version information
                .build();
    }

    @Bean
    public Docket createWxRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("微信管理接口")
                .apiInfo(apiWxInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_WX_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/weixin/.*"))//可以根据url路径设置哪些请求加入文档,忽略哪些请求
                .build();
    }
    private ApiInfo apiWxInfo() {
        return new ApiInfoBuilder()
                .title("微信管理接口")//设置文档的标题
                .description("微信开发接口实现的文档")//设置文档的描述->1.Overview
                .version(WX_VERSION)//设置文档的版本信息-> 1.1 Version information
                .build();
    }
}

猜你喜欢

转载自blog.csdn.net/u012869196/article/details/83897772