package com.softwarebr.nunu.config;

import com.brframework.commonweb.core.SwaggerContext;
import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.List;

/**
 * api前端Swagger配置
 * @Author laolian
 * @Date 2019-8-28 09:44:32
 * Swagger api生成
 */
@Configuration
@Data
public class ApiSwaggerConfig {

    @Value("${swagger.enable}")
    private boolean enable;
    private String groupName = "api";
    private String packageName = "com.softwarebr.nunu.web.api";
    private String title = "api接口文档";
    private String description = "api接口文档";
    private String termsOfServiceUrl = "";
    private String version = "1.0";

    private String contactName = "beiru";
    private String contactUrl = "https://www.software-br.com";
    private String contactEmail = "";



    @Bean("apiDocket")
    public Docket api() {

        List<Parameter> list = Lists.newArrayList();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("Authorization").description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        ParameterBuilder requestFlagPar = new ParameterBuilder();
        requestFlagPar.name("request-flag").description("请求标记").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        list.add(requestFlagPar.build());
        list.add(tokenPar.build());

        return SwaggerContext.createDocket(groupName, packageName, apiInfo(), list, enable);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)//大标题
                .description(description)//详细描述
                .version(version)//版本
                .termsOfServiceUrl(termsOfServiceUrl)
                .contact(new Contact(contactName, contactUrl, contactEmail))//作者
                .license("The Apache License, Version 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
                .build();
    }

}
