package com.ssj.aijia.config;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
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;

/**
 * 
 * 类名称：SpringSwaggerConfig<br>
 * 类描述：Swagger配置<br>
 * @version v1.0
 *
 */
@EnableSwagger2
@Configuration
public class SpringSwaggerConfig  extends WebMvcConfigurerAdapter {
    @Autowired
    private  RequestApiLogInterceptor   requestApiLogInterceptor;
    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        //为controller包路径
        .apis(RequestHandlerSelectors.basePackage("com.ssj"))
        .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
        .paths(PathSelectors.any())
        .build();
    }
    
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
        .title("爱加APP接口文档")//swagger的title
        .description("爱加 Restful接口文档")//自己定义
        .termsOfServiceUrl("https://www.sharingschool.com/")//自己定义
        .version("2.0")
        .build(); 
        
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration addInterceptor = registry.addInterceptor(requestApiLogInterceptor);

    }
   
    
}
