mirror of https://github.com/elunez/eladmin
[代码优化](v2.6):update swagger
parent
8bb800c68e
commit
a1e8005499
|
@ -16,6 +16,7 @@
|
|||
package me.zhengjie.config;
|
||||
|
||||
import com.fasterxml.classmate.TypeResolver;
|
||||
import com.google.common.base.Predicates;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
@ -33,10 +34,8 @@ 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static springfox.documentation.schema.AlternateTypeRules.newRule;
|
||||
|
||||
|
@ -52,32 +51,20 @@ public class SwaggerConfig {
|
|||
@Value("${jwt.header}")
|
||||
private String tokenHeader;
|
||||
|
||||
@Value("${jwt.token-start-with}")
|
||||
private String tokenStartWith;
|
||||
|
||||
@Value("${swagger.enabled}")
|
||||
private Boolean enabled;
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("all")
|
||||
public Docket createRestApi() {
|
||||
// ParameterBuilder ticketPar = new ParameterBuilder();
|
||||
//// List<Parameter> pars = new ArrayList<>();
|
||||
//// ticketPar.name(tokenHeader).description("token")
|
||||
//// .modelRef(new ModelRef("string"))
|
||||
//// .parameterType("header")
|
||||
//// .defaultValue(tokenStartWith + " ")
|
||||
//// .required(true)
|
||||
//// .build();
|
||||
// pars.add(ticketPar.build());
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.enable(enabled)
|
||||
.pathMapping("/")
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
// .paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
// .globalOperationParameters(pars)
|
||||
//添加登陆认证
|
||||
.securitySchemes(securitySchemes())
|
||||
.securityContexts(securityContexts());
|
||||
|
@ -87,7 +74,7 @@ public class SwaggerConfig {
|
|||
return new ApiInfoBuilder()
|
||||
.description("一个简单且易上手的 Spring boot 后台管理框架")
|
||||
.title("EL-ADMIN 接口文档")
|
||||
.version("2.4")
|
||||
.version("2.6")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -104,14 +91,14 @@ public class SwaggerConfig {
|
|||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
// ^(?!auth).*$ 表示所有包含auth的接口不需要使用securitySchemes即不需要带token
|
||||
// ^标识开始 ()里是一子表达式 ?!/auth表示匹配不是/auth的位置,匹配上则添加请求头,注意路径已/开头 .表示任意字符 *表示前面的字符匹配多次 $标识结束
|
||||
securityContexts.add(getContextByPath("^(?!/auth).*$"));
|
||||
securityContexts.add(getContextByPath());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
private SecurityContext getContextByPath(String pathRegex) {
|
||||
private SecurityContext getContextByPath() {
|
||||
return SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex(pathRegex))
|
||||
.forPaths(PathSelectors.regex("^(?!/auth).*$"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue