Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
b0dbdee9
提交
b0dbdee9
authored
7月 11, 2022
作者:
mry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(web): swagger解析
上级
ea3f75eb
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
81 行增加
和
79 行删除
+81
-79
AttributeInVo.java
...ain/java/org/matrix/vo/swaggerEntityVo/AttributeInVo.java
+1
-1
AttributeOutVo.java
.../vo/swaggerEntityVo/definitionsEntity/AttributeOutVo.java
+2
-2
DefinitionsVo.java
...x/vo/swaggerEntityVo/definitionsEntity/DefinitionsVo.java
+1
-1
PropertiesVo.java
...ix/vo/swaggerEntityVo/definitionsEntity/PropertiesVo.java
+2
-2
CodeStatusVo.java
...trix/vo/swaggerEntityVo/responsesEntity/CodeStatusVo.java
+2
-2
ResponsesVo.java
...atrix/vo/swaggerEntityVo/responsesEntity/ResponsesVo.java
+1
-1
PathVo.java
...a/org/matrix/vo/swaggerEntityVo/swaggerEntity/PathVo.java
+2
-2
SwaggerOuter.java
...matrix/vo/swaggerEntityVo/swaggerEntity/SwaggerOuter.java
+2
-2
TagSummary.java
...g/matrix/vo/swaggerEntityVo/swaggerEntity/TagSummary.java
+1
-1
SwaggerController.java
...ava/org/matrix/autotest/controller/SwaggerController.java
+67
-65
没有找到文件。
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/AttributeInVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/AttributeInVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/definitionsEntity/AttributeOutVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/definitionsEntity/AttributeOutVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
definitionsEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
definitionsEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.matrix.
autotest
.swaggerEntityVo.AttributeInVo
;
import
org.matrix.
vo
.swaggerEntityVo.AttributeInVo
;
import
java.util.List
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/definitionsEntity/DefinitionsVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/definitionsEntity/DefinitionsVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
definitionsEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
definitionsEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/definitionsEntity/PropertiesVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/definitionsEntity/PropertiesVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
definitionsEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
definitionsEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.matrix.
autotest
.swaggerEntityVo.AttributeInVo
;
import
org.matrix.
vo
.swaggerEntityVo.AttributeInVo
;
/**
* 属性名称与属性内部
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/responsesEntity/CodeStatusVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/responsesEntity/CodeStatusVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
responsesEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
responsesEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.matrix.
autotest
.swaggerEntityVo.AttributeInVo
;
import
org.matrix.
vo
.swaggerEntityVo.AttributeInVo
;
/**
* @author mruny
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/responsesEntity/ResponsesVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/responsesEntity/ResponsesVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
responsesEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
responsesEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/swaggerEntity/PathVo.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/swaggerEntity/PathVo.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
swaggerEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
swaggerEntity
;
import
com.alibaba.fastjson.JSONArray
;
import
io.swagger.annotations.ApiModel
;
...
...
@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.matrix.
autotest
.swaggerEntityVo.responsesEntity.ResponsesVo
;
import
org.matrix.
vo
.swaggerEntityVo.responsesEntity.ResponsesVo
;
import
java.util.List
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/swaggerEntity/SwaggerOuter.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/swaggerEntity/SwaggerOuter.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
swaggerEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
swaggerEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.matrix.
autotest
.swaggerEntityVo.definitionsEntity.DefinitionsVo
;
import
org.matrix.
vo
.swaggerEntityVo.definitionsEntity.DefinitionsVo
;
import
java.util.List
;
...
...
kt-
web/src/main/java/org/matrix/autotest
/swaggerEntityVo/swaggerEntity/TagSummary.java
→
kt-
database/src/main/java/org/matrix/vo
/swaggerEntityVo/swaggerEntity/TagSummary.java
浏览文件 @
b0dbdee9
package
org
.
matrix
.
autotest
.
swaggerEntityVo
.
swaggerEntity
;
package
org
.
matrix
.
vo
.
swaggerEntityVo
.
swaggerEntity
;
import
com.alibaba.fastjson.JSONArray
;
import
io.swagger.annotations.ApiModel
;
...
...
kt-web/src/main/java/org/matrix/autotest/controller/SwaggerController.java
浏览文件 @
b0dbdee9
...
...
@@ -5,15 +5,15 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.matrix.
autotest
.swaggerEntityVo.AttributeInVo
;
import
org.matrix.
autotest
.swaggerEntityVo.definitionsEntity.AttributeOutVo
;
import
org.matrix.
autotest
.swaggerEntityVo.definitionsEntity.DefinitionsVo
;
import
org.matrix.
autotest
.swaggerEntityVo.definitionsEntity.PropertiesVo
;
import
org.matrix.
autotest
.swaggerEntityVo.responsesEntity.CodeStatusVo
;
import
org.matrix.
autotest
.swaggerEntityVo.responsesEntity.ResponsesVo
;
import
org.matrix.
autotest
.swaggerEntityVo.swaggerEntity.PathVo
;
import
org.matrix.
autotest
.swaggerEntityVo.swaggerEntity.SwaggerOuter
;
import
org.matrix.
autotest
.swaggerEntityVo.swaggerEntity.TagSummary
;
import
org.matrix.
vo
.swaggerEntityVo.AttributeInVo
;
import
org.matrix.
vo
.swaggerEntityVo.definitionsEntity.AttributeOutVo
;
import
org.matrix.
vo
.swaggerEntityVo.definitionsEntity.DefinitionsVo
;
import
org.matrix.
vo
.swaggerEntityVo.definitionsEntity.PropertiesVo
;
import
org.matrix.
vo
.swaggerEntityVo.responsesEntity.CodeStatusVo
;
import
org.matrix.
vo
.swaggerEntityVo.responsesEntity.ResponsesVo
;
import
org.matrix.
vo
.swaggerEntityVo.swaggerEntity.PathVo
;
import
org.matrix.
vo
.swaggerEntityVo.swaggerEntity.SwaggerOuter
;
import
org.matrix.
vo
.swaggerEntityVo.swaggerEntity.TagSummary
;
import
org.matrix.exception.GlobalException
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -48,68 +48,70 @@ public class SwaggerController {
@ApiOperation
(
"获取并解析swagger数据"
)
public
JSONObject
handleSwagger
(
@RequestParam
String
url
)
{
String
loadJson
=
loadJson
(
url
);
JSONObject
swaggerJson
=
JSONObject
.
parseObject
(
loadJson
);
SwaggerOuter
json
=
new
SwaggerOuter
();
String
host
=
String
.
valueOf
(
swaggerJson
.
get
(
"host"
));
json
.
setHost
(
host
);
String
basePath
=
String
.
valueOf
(
swaggerJson
.
get
(
"basePath"
));
json
.
setBasePath
(
basePath
);
List
<
DefinitionsVo
>
definitions
=
handleDefinitions
(
swaggerJson
);
json
.
setDefinitions
(
definitions
);
JSONObject
paths
=
swaggerJson
.
getJSONObject
(
"paths"
);
List
<
PathVo
>
list
=
new
ArrayList
<>();
if
(
paths
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
stringObjectEntry
:
paths
.
entrySet
())
{
String
pathUrl
=
stringObjectEntry
.
getKey
();
//请求方式
JSONObject
pathJson
=
paths
.
getJSONObject
(
pathUrl
);
Set
<
String
>
methodSets
=
pathJson
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
methodSets
))
{
for
(
String
httpMethod
:
methodSets
)
{
PathVo
pathVo
=
new
PathVo
();
JSONObject
methodJson
=
pathJson
.
getJSONObject
(
httpMethod
);
JSONArray
tags
=
methodJson
.
getJSONArray
(
"tags"
);
String
summary
=
methodJson
.
getString
(
"summary"
);
JSONArray
parameters
=
methodJson
.
getJSONArray
(
"parameters"
);
List
<
ResponsesVo
>
responsesVos
=
handleResponse
(
methodJson
);
String
operationId
=
methodJson
.
getString
(
"operationId"
);
String
deprecated
=
methodJson
.
getString
(
"deprecated"
);
JSONArray
consumes
=
methodJson
.
getJSONArray
(
"consumes"
);
JSONArray
produces
=
methodJson
.
getJSONArray
(
"produces"
);
JSONArray
security
=
methodJson
.
getJSONArray
(
"security"
);
pathVo
.
setTags
(
tags
);
pathVo
.
setHttpMethod
(
httpMethod
);
pathVo
.
setPathUrl
(
pathUrl
);
pathVo
.
setSummary
(
summary
);
pathVo
.
setOperationId
(
operationId
);
pathVo
.
setConsumes
(
consumes
);
pathVo
.
setParameters
(
parameters
);
pathVo
.
setResponses
(
responsesVos
);
pathVo
.
setDeprecated
(
deprecated
);
pathVo
.
setSecurity
(
security
);
pathVo
.
setProduces
(
produces
);
list
.
add
(
pathVo
);
if
(
loadJson
!=
null
&&
!
""
.
equals
(
loadJson
)){
JSONObject
swaggerJson
=
JSONObject
.
parseObject
(
loadJson
);
String
host
=
String
.
valueOf
(
swaggerJson
.
get
(
"host"
));
json
.
setHost
(
host
);
String
basePath
=
String
.
valueOf
(
swaggerJson
.
get
(
"basePath"
));
json
.
setBasePath
(
basePath
);
List
<
DefinitionsVo
>
definitions
=
handleDefinitions
(
swaggerJson
);
json
.
setDefinitions
(
definitions
);
JSONObject
paths
=
swaggerJson
.
getJSONObject
(
"paths"
);
List
<
PathVo
>
list
=
new
ArrayList
<>();
if
(
paths
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
stringObjectEntry
:
paths
.
entrySet
())
{
String
pathUrl
=
stringObjectEntry
.
getKey
();
//请求方式
JSONObject
pathJson
=
paths
.
getJSONObject
(
pathUrl
);
Set
<
String
>
methodSets
=
pathJson
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
methodSets
))
{
for
(
String
httpMethod
:
methodSets
)
{
PathVo
pathVo
=
new
PathVo
();
JSONObject
methodJson
=
pathJson
.
getJSONObject
(
httpMethod
);
JSONArray
tags
=
methodJson
.
getJSONArray
(
"tags"
);
String
summary
=
methodJson
.
getString
(
"summary"
);
JSONArray
parameters
=
methodJson
.
getJSONArray
(
"parameters"
);
List
<
ResponsesVo
>
responsesVos
=
handleResponse
(
methodJson
);
String
operationId
=
methodJson
.
getString
(
"operationId"
);
String
deprecated
=
methodJson
.
getString
(
"deprecated"
);
JSONArray
consumes
=
methodJson
.
getJSONArray
(
"consumes"
);
JSONArray
produces
=
methodJson
.
getJSONArray
(
"produces"
);
JSONArray
security
=
methodJson
.
getJSONArray
(
"security"
);
pathVo
.
setTags
(
tags
);
pathVo
.
setHttpMethod
(
httpMethod
);
pathVo
.
setPathUrl
(
pathUrl
);
pathVo
.
setSummary
(
summary
);
pathVo
.
setOperationId
(
operationId
);
pathVo
.
setConsumes
(
consumes
);
pathVo
.
setParameters
(
parameters
);
pathVo
.
setResponses
(
responsesVos
);
pathVo
.
setDeprecated
(
deprecated
);
pathVo
.
setSecurity
(
security
);
pathVo
.
setProduces
(
produces
);
list
.
add
(
pathVo
);
}
}
}
}
}
List
<
TagSummary
>
tagSummaryList
=
new
ArrayList
<>();
//stream取出key:tags,value:summary
Map
<
JSONArray
,
List
<
PathVo
>>
collect
=
list
.
stream
()
.
filter
(
pathVo
->
pathVo
!=
null
&&
pathVo
.
getTags
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
PathVo:
:
getTags
));
Set
<
JSONArray
>
tags
=
collect
.
keySet
();
for
(
JSONArray
tag
:
tags
)
{
TagSummary
tagSummary
=
new
TagSummary
();
List
<
PathVo
>
pathVos
=
collect
.
get
(
tag
);
tagSummary
.
setTag
(
tag
);
for
(
PathVo
pathVO
:
pathVos
)
{
pathVO
.
setTags
(
null
);
List
<
TagSummary
>
tagSummaryList
=
new
ArrayList
<>();
//stream取出key:tags,value:summary
Map
<
JSONArray
,
List
<
PathVo
>>
collect
=
list
.
stream
()
.
filter
(
pathVo
->
pathVo
!=
null
&&
pathVo
.
getTags
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
PathVo:
:
getTags
));
Set
<
JSONArray
>
tags
=
collect
.
keySet
();
for
(
JSONArray
tag
:
tags
)
{
TagSummary
tagSummary
=
new
TagSummary
();
List
<
PathVo
>
pathVos
=
collect
.
get
(
tag
);
tagSummary
.
setTag
(
tag
);
for
(
PathVo
pathVO
:
pathVos
)
{
pathVO
.
setTags
(
null
);
}
tagSummary
.
setPaths
(
pathVos
);
tagSummaryList
.
add
(
tagSummary
);
}
tagSummary
.
setPaths
(
pathVos
);
tagSummaryList
.
add
(
tagSummary
);
json
.
setTagSummaryList
(
tagSummaryList
);
}
json
.
setTagSummaryList
(
tagSummaryList
);
return
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
json
));
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论