package com.fkzy.warn.common.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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;

/**
 * swagger 配置类
 *
 * @author yuyantian
 * @date 2021/9/7 14:30
 */
@Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class Swagger {

    @Value("${server.servlet-path}")
    private String servletPath;

    @Bean
    public Docket createSwaggerApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(myApi()).select().apis(
            RequestHandlerSelectors.basePackage("com.fkzy.warn")).paths(
            PathSelectors.any())
            .build().pathMapping(servletPath);
    }

    public ApiInfo myApi() {
        return new ApiInfoBuilder().title("风控之眼-运营管理平台-接口")
            .contact(new Contact("", "http", "@qq.com")).description("demo rest接口")
            .version("1.0")
            .build();
    }
}
