Spring Boot -- Swagger之接口分组

来源:互联网 发布:淘宝的体检中心在哪里 编辑:程序博客网 时间:2024/06/05 00:34

在一些情况,需要对整套REST API进行分组.这时可以在SwaggerConfig中进行设置

@Configuration@EnableSwagger2public class SwaggerConfig {    @Bean    public Docket createRestApi() {        return new Docket(DocumentationType.SWAGGER_2)                .groupName("group1")                .apiInfo(apiInfo())                .select()                .apis(RequestHandlerSelectors.basePackage("com.yucoang.controller"))                .paths(PathSelectors.regex("/api/.*"))                .build();    }    @Bean    public Docket createRestApi2() {        return new Docket(DocumentationType.SWAGGER_2)                .groupName("group2")                .apiInfo(apiInfo2())                .select()                .apis(RequestHandlerSelectors.basePackage("com.yucoang.controller2"))                .paths(PathSelectors.regex("/nologin/.*"))                .build();    }    private ApiInfo apiInfo() {        ...    }        private ApiInfo apiInfo2() {        ...    }}

这里写图片描述

通过Docket.groupName(String groupName)设置分组名后便可分组.
分组后,可以对不同组的API设置不同的信息,如项目信息(apiInfo),全局参数(globalOperationParameters),全局返回值(globalResponseMessage).
分组规则可以通过apis()或paths().设定

原创粉丝点击