Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
dc6544b5
提交
dc6544b5
authored
4月 12, 2022
作者:
mry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(web): 代码优化
上级
bbe13e5e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
21 行删除
+24
-21
SwaggerController.java
...ava/org/matrix/autotest/controller/SwaggerController.java
+24
-21
没有找到文件。
kt-web/src/main/java/org/matrix/autotest/controller/SwaggerController.java
浏览文件 @
dc6544b5
...
@@ -4,14 +4,14 @@ import com.alibaba.fastjson.JSON;
...
@@ -4,14 +4,14 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.parser.Feature
;
import
com.alibaba.fastjson.parser.Feature
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.models.Swagger
;
import
org.matrix.autotest.swaggerEntity.ParameterVo
;
import
org.matrix.autotest.swaggerEntity.*
;
import
org.matrix.autotest.swaggerEntity.PathInfoVo
;
import
org.matrix.autotest.swaggerEntity.ResponseVo
;
import
org.matrix.database.entity.Environment
;
import
org.matrix.database.entity.Environment
;
import
org.matrix.database.service.IEnvironmentService
;
import
org.matrix.database.service.IEnvironmentService
;
import
org.matrix.database.vo.CommonPage
;
import
org.matrix.database.vo.CommonPage
;
...
@@ -52,7 +52,7 @@ public class SwaggerController {
...
@@ -52,7 +52,7 @@ public class SwaggerController {
* @return 封装好的接口信息
* @return 封装好的接口信息
*/
*/
public
static
List
<
PathInfoVo
>
getPathInfo
(
JSONObject
swaggerJson
)
{
public
static
List
<
PathInfoVo
>
getPathInfo
(
JSONObject
swaggerJson
)
{
L
ong
i
=
0L
;
l
ong
i
=
0L
;
JSONObject
paths
=
swaggerJson
.
getJSONObject
(
"paths"
);
JSONObject
paths
=
swaggerJson
.
getJSONObject
(
"paths"
);
String
host
=
String
.
valueOf
(
swaggerJson
.
get
(
"host"
));
String
host
=
String
.
valueOf
(
swaggerJson
.
get
(
"host"
));
String
basePath
=
String
.
valueOf
(
swaggerJson
.
get
(
"basePath"
));
String
basePath
=
String
.
valueOf
(
swaggerJson
.
get
(
"basePath"
));
...
@@ -94,6 +94,17 @@ public class SwaggerController {
...
@@ -94,6 +94,17 @@ public class SwaggerController {
return
list
;
return
list
;
}
}
/**
* 提取公共的$ref解析
*
* @param childMap properties中封装的json
* @return swagger中$ref值对应的value对象名称
*/
private
static
String
getRef
(
JSONObject
childMap
)
{
String
childRef
=
childMap
.
getString
(
"$ref"
);
return
childRef
.
substring
(
14
);
}
/**
/**
* 解析响应数据
* 解析响应数据
*
*
...
@@ -138,16 +149,14 @@ public class SwaggerController {
...
@@ -138,16 +149,14 @@ public class SwaggerController {
resp
.
setType
(
StringUtils
.
isBlank
(
respType
)
?
"object"
:
respType
);
resp
.
setType
(
StringUtils
.
isBlank
(
respType
)
?
"object"
:
respType
);
resp
.
setRequired
(
respMap
.
getBooleanValue
(
"required"
));
resp
.
setRequired
(
respMap
.
getBooleanValue
(
"required"
));
if
(
respMap
.
containsKey
(
"$ref"
))
{
if
(
respMap
.
containsKey
(
"$ref"
))
{
String
childRef
=
respMap
.
getString
(
"$ref"
);
String
childDef
=
getRef
(
respMap
);
String
childDef
=
childRef
.
substring
(
14
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childProperties
=
childDefJson
.
getJSONObject
(
"properties"
);
JSONObject
childProperties
=
childDefJson
.
getJSONObject
(
"properties"
);
getRef
(
refMap
,
childProperties
,
resp
,
childDef
,
childDefJson
);
getRef
(
refMap
,
childProperties
,
resp
,
childDef
,
childDefJson
);
}
else
if
(
"array"
.
equalsIgnoreCase
(
respType
))
{
}
else
if
(
"array"
.
equalsIgnoreCase
(
respType
))
{
JSONObject
items
=
respMap
.
getJSONObject
(
"items"
);
JSONObject
items
=
respMap
.
getJSONObject
(
"items"
);
if
(
items
.
containsKey
(
"$ref"
))
{
if
(
items
.
containsKey
(
"$ref"
))
{
String
itemRef
=
items
.
getString
(
"$ref"
);
String
itemDef
=
getRef
(
items
);
String
itemDef
=
itemRef
.
substring
(
14
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
childProperties
=
itemDefJson
.
getJSONObject
(
"properties"
);
JSONObject
childProperties
=
itemDefJson
.
getJSONObject
(
"properties"
);
getRef
(
refMap
,
childProperties
,
resp
,
itemDef
,
itemDefJson
);
getRef
(
refMap
,
childProperties
,
resp
,
itemDef
,
itemDefJson
);
...
@@ -182,8 +191,7 @@ public class SwaggerController {
...
@@ -182,8 +191,7 @@ public class SwaggerController {
childResp
.
add
(
resp
);
childResp
.
add
(
resp
);
parentResp
.
setChildResp
(
childResp
);
parentResp
.
setChildResp
(
childResp
);
if
(
childMap
.
containsKey
(
"$ref"
))
{
if
(
childMap
.
containsKey
(
"$ref"
))
{
String
childRef
=
childMap
.
getString
(
"$ref"
);
String
childDef
=
getRef
(
childMap
);
String
childDef
=
childRef
.
substring
(
14
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
pro
=
childDefJson
.
getJSONObject
(
"properties"
);
JSONObject
pro
=
childDefJson
.
getJSONObject
(
"properties"
);
//additionalProperties
//additionalProperties
...
@@ -193,8 +201,7 @@ public class SwaggerController {
...
@@ -193,8 +201,7 @@ public class SwaggerController {
}
else
if
(
"array"
.
equalsIgnoreCase
(
childType
))
{
}
else
if
(
"array"
.
equalsIgnoreCase
(
childType
))
{
JSONObject
items
=
childMap
.
getJSONObject
(
"items"
);
JSONObject
items
=
childMap
.
getJSONObject
(
"items"
);
if
(
items
.
containsKey
(
"$ref"
))
{
if
(
items
.
containsKey
(
"$ref"
))
{
String
itemRef
=
items
.
getString
(
"$ref"
);
String
itemDef
=
getRef
(
items
);
String
itemDef
=
itemRef
.
substring
(
14
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
if
(
pro
!=
null
&&
!
itemDef
.
equalsIgnoreCase
(
parentVoName
))
{
if
(
pro
!=
null
&&
!
itemDef
.
equalsIgnoreCase
(
parentVoName
))
{
...
@@ -259,8 +266,7 @@ public class SwaggerController {
...
@@ -259,8 +266,7 @@ public class SwaggerController {
childParam
.
setType
(
StringUtils
.
isBlank
(
type
)
?
"object"
:
type
);
childParam
.
setType
(
StringUtils
.
isBlank
(
type
)
?
"object"
:
type
);
childParam
.
setRequired
(
proMap
.
getBooleanValue
(
"required"
));
childParam
.
setRequired
(
proMap
.
getBooleanValue
(
"required"
));
if
(
proMap
.
containsKey
(
"$ref"
))
{
if
(
proMap
.
containsKey
(
"$ref"
))
{
String
childRef
=
proMap
.
getString
(
"$ref"
);
String
childDef
=
getRef
(
proMap
);
String
childDef
=
childRef
.
substring
(
14
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childProperties
=
childDefJson
.
getJSONObject
(
"properties"
);
JSONObject
childProperties
=
childDefJson
.
getJSONObject
(
"properties"
);
if
(
childProperties
!=
null
)
{
if
(
childProperties
!=
null
)
{
...
@@ -269,8 +275,7 @@ public class SwaggerController {
...
@@ -269,8 +275,7 @@ public class SwaggerController {
}
else
if
(
"array"
.
equalsIgnoreCase
(
type
))
{
}
else
if
(
"array"
.
equalsIgnoreCase
(
type
))
{
JSONObject
items
=
proMap
.
getJSONObject
(
"items"
);
JSONObject
items
=
proMap
.
getJSONObject
(
"items"
);
if
(
items
.
containsKey
(
"$ref"
))
{
if
(
items
.
containsKey
(
"$ref"
))
{
String
itemRef
=
items
.
getString
(
"$ref"
);
String
itemDef
=
getRef
(
items
);
String
itemDef
=
itemRef
.
substring
(
14
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
if
(
pro
!=
null
)
{
if
(
pro
!=
null
)
{
...
@@ -296,16 +301,15 @@ public class SwaggerController {
...
@@ -296,16 +301,15 @@ public class SwaggerController {
for
(
String
key
:
childSet
)
{
for
(
String
key
:
childSet
)
{
JSONObject
childMap
=
childProperties
.
getJSONObject
(
key
);
JSONObject
childMap
=
childProperties
.
getJSONObject
(
key
);
ParameterVo
resp
=
new
ParameterVo
();
ParameterVo
resp
=
new
ParameterVo
();
resp
.
setName
(
key
);
resp
.
setDescription
(
childMap
.
getString
(
"description"
));
resp
.
setDescription
(
childMap
.
getString
(
"description"
));
String
childType
=
childMap
.
getString
(
"type"
);
String
childType
=
childMap
.
getString
(
"type"
);
resp
.
setName
(
key
);
resp
.
setType
(
StringUtils
.
isNotBlank
(
childType
)
?
childType
:
childJson
.
getString
(
"type"
));
resp
.
setType
(
StringUtils
.
isNotBlank
(
childType
)
?
childType
:
childJson
.
getString
(
"type"
));
resp
.
setRequired
(
childMap
.
getBooleanValue
(
"required"
));
resp
.
setRequired
(
childMap
.
getBooleanValue
(
"required"
));
paramList
.
add
(
resp
);
paramList
.
add
(
resp
);
parentResp
.
setChildParam
(
paramList
);
parentResp
.
setChildParam
(
paramList
);
if
(
childMap
.
containsKey
(
"$ref"
))
{
if
(
childMap
.
containsKey
(
"$ref"
))
{
String
childRef
=
childMap
.
getString
(
"$ref"
);
String
childDef
=
getRef
(
childMap
);
String
childDef
=
childRef
.
substring
(
14
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
childDefJson
=
refMap
.
get
(
childDef
);
JSONObject
pro
=
childDefJson
.
getJSONObject
(
"properties"
);
JSONObject
pro
=
childDefJson
.
getJSONObject
(
"properties"
);
//additionalProperties
//additionalProperties
...
@@ -315,8 +319,7 @@ public class SwaggerController {
...
@@ -315,8 +319,7 @@ public class SwaggerController {
}
else
if
(
"array"
.
equalsIgnoreCase
(
childType
))
{
}
else
if
(
"array"
.
equalsIgnoreCase
(
childType
))
{
JSONObject
items
=
childMap
.
getJSONObject
(
"items"
);
JSONObject
items
=
childMap
.
getJSONObject
(
"items"
);
if
(
items
.
containsKey
(
"$ref"
))
{
if
(
items
.
containsKey
(
"$ref"
))
{
String
itemRef
=
items
.
getString
(
"$ref"
);
String
itemDef
=
getRef
(
items
);
String
itemDef
=
itemRef
.
substring
(
14
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
itemDefJson
=
refMap
.
get
(
itemDef
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
JSONObject
pro
=
itemDefJson
.
getJSONObject
(
"properties"
);
if
(
pro
!=
null
&&
!
itemDef
.
equalsIgnoreCase
(
parentVoName
))
{
if
(
pro
!=
null
&&
!
itemDef
.
equalsIgnoreCase
(
parentVoName
))
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论