swagger2的分组配置

当微服务的服务越来越多swagger2展示的越来越长这时候需要进行分页展示
swagger2头上有下拉框可以groupName进行分组展示

java代码代码:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

 	@Bean
    public Docket createRestApi() {
 		
 		
        return new Docket(DocumentationType.SWAGGER_2)
        		.globalOperationParameters(operationParameters())
        		.groupName("第一个接口服务页面")
        		.genericModelSubstitutes(DeferredResult.class)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tan.oauth2.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(" createRestApi  Spring Boot中使用Swagger2构建RESTful APIs")
                .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/")
                .termsOfServiceUrl("http://github.com/")
                .contact("程序猿痛苦")
                .version("1.0")
                .build();
    }
    @Bean
    public Docket openRestApi() {
    	Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() {
            @Override
            public boolean apply(RequestHandler input) {

// Class<?> declaringClass = input.declaringClass();
// if (declaringClass == BasicErrorController.class)// 排除
// return false;
// if(declaringClass.isAnnotationPresent(ApiOperation.class)) // 被注解的类
// return true;
// if(input.isAnnotatedWith(ResponseBody.class)) // 被注解的方法
// return true;
// if (input.isAnnotatedWith(ApiOperation.class))//只有添加了ApiOperation注解的method才在API中显示
// return true;
if (input.isAnnotatedWith(ApiOperation.class))//只有添加了ApiOperation注解的method才在API中显示
return true;
return false;
}
};
return new Docket(DocumentationType.SWAGGER_2)
.groupName(“第二个接口服务页面”)
.genericModelSubstitutes(DeferredResult.class)
.apiInfo(openapiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(“com.tan.oauth2.controller2”))
// .apis(predicate)
.paths(PathSelectors.any())
.build();
}
private ApiInfo openapiInfo() {
return new ApiInfoBuilder()
.title(“openRestApi Spring Boot中使用Swagger2构建RESTful APIs”)
.description(“更多Spring Boot相关文章请关注:http://blog.didispace.com/”)
.termsOfServiceUrl(“http://github.com/”)
.contact(“程序猿痛苦”)
.version(“1.0”)
.build();
}

    public  List<Parameter> operationParameters() {
    	//添加head参数start
    	ParameterBuilder tokenPar = new ParameterBuilder();
    	List<Parameter> pars = new ArrayList<Parameter>();
    	tokenPar.name("x-access-token")
    	.description("令牌")
    	.modelRef(new ModelRef("string"))
    	.parameterType("header")
    	.required(false)
    	.build();
    	pars.add(tokenPar.build());
    	//添加head参数end
    	return pars;  
    }

}

pom.xml文件配置

             <dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
	</dependency>

	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
	</dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值