package com.chy.borrow.config;


import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${swagger2.enable}")
    private boolean enable;
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("借阅系统Service")
                //版本号
                .version("1.0")
                //描述
                .description("API 描述")
                .build();
    }
    @Bean
    public Docket createRestApi() {

        Predicate<RequestHandler> selector = RequestHandlerSelectors.basePackage("com.chy.borrow.controller");
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .groupName("借阅接口")
                .select()
                //.apis(Predicates.or(selector))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .enable(enable);
    }



}
