package com.mortals.xhx.base.framework.config;

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//import io.swagger.annotations.ApiOperation;
//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;

//@Configuration
//@EnableSwagger2
//@EnableWebMvc // 这个注解spring4.0+用
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
// 1、这个配置主要为了生产环境不生成swagger文档，请在iot-*-develop.yml，iot-*-product.yml文件中增加
// 2、在权限检查拦截器上增加swagger的URL放开,如下：
// application.auth.unloginUrl=/swagger-ui*
// application.auth.uncheckUrl=/swagger-ui*
public class SwaggerConfiguration implements WebMvcConfigurer {

//	@Bean
//	public Docket createRestApi() {
//		Set<String> producesList = new HashSet<>();
//		producesList.add("application/json");
//		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).produces(producesList).select()
//				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any())
//				.build();
//	}

	// 文档信息说明和个人信息配置
//	private ApiInfo apiInfo() {
//		return new ApiInfoBuilder().title("PLM服务").description("PLM服务API")
//				.contact(new Contact("yuanjiaquan", "", "yuanjiaquan@gewuzhixiang.com")).version("1.0").build();
//	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 增加swagger-ui资源
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

}