package cn.enilu.flash.api.config;

import io.swagger.models.auth.In;
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.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;
import java.util.List;

/**
 * swagger在线文档配置<br>
 * 项目启动后可通过地址：http://host:ip/swagger-ui.html 查看在线文档
 *
 * @author enilu
 * @version 2018-07-24
 */

@EnableOpenApi
@Configuration
public class SwaggerConfig {


    @Bean
    public Docket frontApi() {
        ApiKey apiKey = new ApiKey("Authorization", "Authorization", In.HEADER.toValue());
        List<SecurityScheme> headers =  Collections.singletonList(apiKey);

        return new Docket(DocumentationType.OAS_30)
                //是否开启，根据环境配置
                .enable(true)
//                .groupName("api")
                .apiInfo(frontApiInfo())
                .select()

                //指定扫描的包
                .apis(RequestHandlerSelectors.basePackage("cn.enilu.flash.api"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(headers);
    }

    /**
     * 前台API信息
     */
    private ApiInfo frontApiInfo() {
        return new ApiInfoBuilder()
                .title("web-flash api")
                .description("快速构建web管理平台")
                .version("v1.0")
                .license("MIT")
                .contact(    //添加开发者的一些信息
                        new Contact("enilu", "http://www.enilu.cn",
                                "eniluzt@qq.com"))
                .build();
    }
}

@@ -453,23 +453,17 @@
 service.
-ApiInfo
+*
 ;%0Aimport
@@ -492,69 +492,28 @@
 on.s
-ervice.ApiKey;%0Aimport springfox.documentation.service.Contact
+pi.DocumentationType
 ;%0Aim
@@ -541,24 +541,28 @@
 ntation.
+spi.
 service.
 Security
@@ -557,76 +557,32 @@
 ice.
-SecurityScheme;%0Aimport springfox.documentation.spi.DocumentationType
+contexts.SecurityContext
 ;%0Aim
@@ -1518,24 +1518,456 @@
 headers)
+.securityContexts(securityContexts());%0A    %7D%0A    /**%0A     * %E6%8E%88%E6%9D%83%E4%BF%A1%E6%81%AF%E5%85%A8%E5%B1%80%E5%BA%94%E7%94%A8%0A     */%0A    private List%3CSecurityContext%3E securityContexts() %7B%0A        return Collections.singletonList(%0A                SecurityContext.builder()%0A                        .securityReferences(Collections.singletonList(new SecurityReference(%22Authorization%22, new AuthorizationScope%5B%5D%7Bnew AuthorizationScope(%22global%22, %22%22)%7D)))%0A                        .build()%0A        )
 ;%0A    %7D
-%0A
 %0A    /**

Fix #I3Z1QT 后端启动后，API接口访问不到后端，中途权限被拦截