package cn.com.ty.lift.ud.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RestController;
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(value = "swagger2Config")
@Import(value = WebMvcConfig.class)
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "aliyun.oss")
    public OssConfigutatioin ossConfigutatioin(){
        return  new OssConfigutatioin();
    }

    @Bean
    @ConfigurationProperties(prefix = "sys.cont")
    public SystemCont systemCont(){
        return  new SystemCont();
    }

    /**
     * 获取微服务名称
     */
    @Value("${spring.application.name}")
    private String appName;

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                // 扫描@RestController接口类
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                // 定义要生成文档的Api的url路径规则
                .paths(PathSelectors.any())
                .build()
                // 设置swagger-ui.html页面上的一些元素信息。
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 标题
                .title(appName + " API")
                // 描述
                .description(appName + "微服务接口文档")
                // 接口文档版本
                .version("1.0").build();
    }
}
