package com.xxfc.platform.order.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.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
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.ArrayList;
import java.util.List;

/**
* @Description : swagger配置配置
* @Author : Mars
* @Date : 2017年9月6日
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${server.port}")
    String port;
	
    /**
     * Every Docket bean is picked up by the swagger-mvc framework - allowing for multiple
     * swagger groups i.e. same code base multiple swagger resource listings.
     */
    @Bean
    public Docket customDocket(){
        List<Parameter> pars = new ArrayList<Parameter>();
    	ParameterBuilder ticketPar = new ParameterBuilder();
    	ticketPar.name("Authorization").description("user Authorization")
    	.modelRef(new ModelRef("string")).parameterType("header")
    	.required(false).build(); //header中的ticket参数非必填，传空也可以

        ParameterBuilder ticketPar2 = new ParameterBuilder();
        ticketPar2.name("x-client-token").description("client Authorization")
                .modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build(); //header中的ticket参数非必填，传空也可以

    	pars.add(ticketPar.build());    //根据每个方法名也知道当前方法在设置什么参数
        pars.add(ticketPar2.build());
 
        return new Docket(DocumentationType.SWAGGER_2)
                .host("10.1.37.248:8765/api/order")
        		.select()
                .apis(RequestHandlerSelectors.basePackage("com.xxfc.platform.order"))
        		//.apis(RequestHandlerSelectors.any())
                .build()  
                .globalOperationParameters(pars)  
                .apiInfo(apiInfo());
    }
    
    ApiInfo apiInfo() {
    	return new ApiInfoBuilder()
            .title("api swagger document")  
            .description("前后端联调swagger api 文档")
            .version("2.1.5.5")
            .build();
    }  
}