package com.philisense.www;

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

import java.util.ArrayList;

/**
 * Swagger3的接口配置
 *
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    // 是否开启swagger，正式环境一般是需要关闭的，可根据springboot的多环境配置进行设置
    @Value(value = "${swagger.enabled}")
    Boolean swaggerEnabled;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                // 是否开启
                .enable(swaggerEnabled).apiInfo(apiInfo()).select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.philisense.www"))
                // 指定路径处理PathSelectors.any()代表所有的路径
                .paths(PathSelectors.any())
                .build();
    }

    Contact contact = new Contact("飞利信","www.philisense.cn","philisense@qq.com");

    /**
     * 配置Swagger 信息 = ApiInfo
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfo("平台文档构建RESTful APIs接口文档",
                "更多请关注：http://localhost:9091/platform_system/swagger-ui/index.html",
                "1.0",
                "http://localhost:9091",
                contact,
                "",
                "",
                new ArrayList<>());
    }
}
