Swagger2 进行分组

Swagger是一个很好的api文档,如果我们的接口过于多,那么一个页面很难展示,查找不方便,那么我们就对swagger进行分组。

分组策略为按包名称分组,另一个是按请求路径进行分类。

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {


//设置显示状态,value是在pom中配置的
@Value("${meinergy.config.swagger:false}")
    private boolean swaggerShow;

    @Bean
    public Docket createRestApiForAll() {
        return new Docket(DocumentationType.SWAGGER_2).enable(swaggerShow).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.tyut.controller"))
                .paths(PathSelectors.any()).build().groupName("所有api").pathMapping("/");
    }

	//根据包进行分组

    @Bean
    public Docket createRestApiForAuth() {
        return new Docket(DocumentationType.SWAGGER_2).enable(swaggerShow).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.tyut.controller.auth"))
                .paths(PathSelectors.any()).build().groupName("用户管理").pathMapping("/");
    }

    @Bean
    public Docket createRestApiForCs() {
        return new Docket(DocumentationType.SWAGGER_2).enable(swaggerShow).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.tyut.controller.cs"))
                .paths(PathSelectors.any()).build().groupName("客户满意度").pathMapping("/");
    }
    
	// 按照路径进行分组
	@Bean
    public Docket web_api_admin() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("admin-api", "系统管理员", "1.0"))
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/api/admin/**"))
                .build()
                .groupName("系统管理员")
                .pathMapping("/");
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("[项目名称]").description("[项目描述]").version("1.0.0").build();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值