/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.multishop.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
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.ArrayList;
import java.util.List;

/**
 * Swagger文档，只有在测试环境才会使用
 * @author LGH
 */
//@Profile("dev")
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfiguration {

	 @Bean
	 public Docket createRestApi() {
		 ParameterBuilder ticketPar = new ParameterBuilder();
		 ParameterBuilder t = new ParameterBuilder();
		 List<Parameter> pars = new ArrayList<Parameter>();
		 ticketPar.name("authorization").description("authorization 拼接： bearer")//Token 以及Authorization 为自定义的参数，session保存的名字是哪个就可以写成那个
				 .modelRef(new ModelRef("string")).parameterType("header")
				 .required(false).build(); //header中的ticket参数非必填，传空也可以
		 t.name("t").description("时间戳")//Token 以及Authorization 为自定义的参数，session保存的名字是哪个就可以写成那个
				 .modelRef(new ModelRef("string")).parameterType("query")
				 .required(true).build(); //header中的ticket参数非必填，传空也可以
		 pars.add(ticketPar.build());
		 pars.add(t.build());
		 return new Docket(DocumentationType.SWAGGER_2)
				 .apiInfo(apiInfo())
				 .select()
				 .apis(RequestHandlerSelectors.basePackage("com.yami"))
				 .paths(PathSelectors.any())
				 .build()
				 .globalOperationParameters(pars);
	 }

	 @Bean
	 public ApiInfo apiInfo() {
	     return new ApiInfoBuilder()
	     .title("海马购商户端接口文档")
	     .description("海马购商户端接口文档")
	     .termsOfServiceUrl("")
	     .contact(new Contact("","", ""))
	     .version("1.0")
	     .build();
	 }
}
