package com.ovit.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author zhangfan
 * @date 2022.04.28 20:55
 */
@ConditionalOnProperty(name = "knife4j.enable", havingValue = "true")
@Configuration
@EnableKnife4j
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Value("${spring.application.name}")
    private String projectName;

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ruoyi")
                )
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置Swagger信息,个性化设置,也可以用默认的
     *
     * @return
     */
    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder().title(projectName + "'s swagger")
                .description("<div style='font-size:14px;color:red;'>"
                        + projectName
                        + " RESTful APIs</div>")
                .termsOfServiceUrl("http://www.group.com")
                .version("1.0")
                .build();
    }
}