Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JAVA小学生-王铁柱
eladmin
提交
a1e80054
E
eladmin
项目概览
JAVA小学生-王铁柱
/
eladmin
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
eladmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a1e80054
编写于
3月 01, 2021
作者:
Z
Zheng Jie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[代码优化](v2.6):update swagger
上级
8bb800c6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
7 addition
and
20 deletion
+7
-20
eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java
...ommon/src/main/java/me/zhengjie/config/SwaggerConfig.java
+7
-20
未找到文件。
eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java
浏览文件 @
a1e80054
...
...
@@ -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
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录