com.zznote.basecommon.common.config.swagger.SwaggerConfig Maven / Gradle / Ivy
The newest version!
package com.zznote.basecommon.common.config.swagger;
import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.List;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean(value = "sysApi")
@Order(value = 1)
public Docket groupRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(groupApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.zznote.base"))
.paths(PathSelectors.any())
.build().securityContexts(Lists.newArrayList(securityContext(), securityContext1())).securitySchemes(Lists.newArrayList(apiTokenKey()));
}
private ApiInfo groupApiInfo() {
return new ApiInfoBuilder()
.title("springboot基础架构接口文档")
.description("采用knife4j作为本快速框架的接口文档")
.termsOfServiceUrl("https://zznote.gitee.io")
.contact(new Contact("zznote", "https://zznote.gitee.io", "[email protected]"))
.version("1.0.0")
.build();
}
/**
* 请求添加头部
* @return
*/
private ApiKey apiTokenKey() {
return new ApiKey("satoken", "token值", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("/.*"))
.build();
}
private SecurityContext securityContext1() {
return SecurityContext.builder()
.securityReferences(defaultAuth1())
.forPaths(PathSelectors.regex("/.*"))
.build();
}
List defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Lists.newArrayList(new SecurityReference("apiToken", authorizationScopes));
}
List defaultAuth1() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Lists.newArrayList(new SecurityReference("apiId", authorizationScopes));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy