/**
 * Copyright (C), 2018-2019, XXX有限公司
 * FileName: SwaggerConfig
 * Author:   pwb
 * Date:     2019/7/12 10:44
 * Description: swagger2配置类
 * History:
 * <author>          <time>          <version>          <desc>
 * frank           修改时间           1.0.0              ycypApp
 */
package com.yx.face.boot.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 〈swagger2配置类〉
 *
 * @author pwb
 * @create 2019/7/12
 * @since 1.0.0
 */

@Configuration
@EnableSwagger2
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class SwaggerConfig {

    @Value("${swagger.enable}")
    private boolean enable;
/*
    //2
    @Bean
    public Docket api() {

        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        tokenPar.name("Authorization").description("AccessToken令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(" com.yx.face.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("机场审核")
                .description("后台服务接口；")
                .contact(new Contact("pwb", "www.baidu.com", "925234379@qq.com"))
                .version("1.0")
                .build();
    }
*/

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .enable(enable)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo())
                .groupName("1.X版本")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yx.face.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("案件分析服务 API")
                .description("后台服务接口")
                .termsOfServiceUrl("http://localhost:8088/")
                .contact(new Contact("pwb", "www.baidu.com", "925234379@qq.com"))
                .version("1.0")
                .build();
    }


}
