package com.unis.homePage.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import com.unis.common.pojo.CommonResult;

import javax.annotation.Resource;

/**
 * 业务相关配置
 *
 *
 **/
@Configuration
public class HomePageConfigure {

    @Resource
    private OpenApiExtensionResolver openApiExtensionResolver;

    /**
     *
     **/
    @Bean(value = "homePageDocApi")
    public Docket homePageDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("首页管理")
                        .description("首页管理")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("UNIS_TEAM","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("1.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("首页管理")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("com.unis.homePage"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("首页管理"));
    }
}
