package com.suntray.oa.app.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import org.springframework.beans.factory.annotation.Value;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import springfox.documentation.service.Contact;
import springfox.documentation.builders.RequestHandlerSelectors;


@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

    @Value("${spring.application.name:default}")
    private String applicationName;

    @Bean
    public Docket docket() {
        // 指定使用Swagger2规范
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        // 简介(支持Markdown语法)
                        .description("地铁公务APP端api")
                        // 服务地址
                        .termsOfServiceUrl("API服务条款")
                        // 作者及联系信息
                        .contact(new Contact("地铁公务", "地铁公务", "地铁公务"))
                        // api版本
                        .version("1.0.0")
                        .build())
                //分组名称(微服务项目可以用微服务名分组)
                .groupName(applicationName)
                .select()
                // 定位api
//                .apis(
//                        RequestHandlerSelectors.basePackage(getProjectBasePackage())
//                                .and(RequestHandlerSelectors.withClassAnnotation(RestController.class)
//                                        .or(RequestHandlerSelectors.withClassAnnotation(Controller.class))
//                                )
//                )
//                .paths(PathSelectors.any())
                .build();

//        docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());
        return docket;
    }
}
