package org.shunt.config;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/** 
* @ClassName: SwaggerConfig 
* @Description: SwaggerConfig配置
* @author caogang
* @date 2021年6月17日 上午9:43:07 
*  
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private List<Parameter> getParameters() {
        Parameter parameter = new ParameterBuilder()
                .name("token")
                .description("token令牌")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build();

        List<Parameter> parameters = CollectionUtil.newArrayList();
        parameters.add(parameter);
        return parameters;
    }

    @Bean
    public Docket defaultApi() {
        List<Parameter> parameters = getParameters();
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(defaultApiInfo())
                .groupName("默认接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.shunt.contorller"))
                .paths(PathSelectors.any())
                .build()
//                .globalOperationParameters(parameters)
                ;
    }

    private ApiInfo defaultApiInfo() {
        return new ApiInfoBuilder()
                .title("Major Doc")
                .description("Major API Doc文档")
                .termsOfServiceUrl("http://www.xxx.com/")
                .contact(new Contact("caggang", "http://www.xxx.com/", ""))
                .version("1.0")
                .build();
    }
}
