Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
0d4bb98e
提交
0d4bb98e
authored
3月 01, 2022
作者:
mry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(web): 修改了部分bug
上级
602ae2eb
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
146 行增加
和
21 行删除
+146
-21
Environment.java
...src/main/java/org/matrix/database/entity/Environment.java
+3
-0
IEnvironmentService.java
...java/org/matrix/database/service/IEnvironmentService.java
+8
-0
EnvironmentServiceImpl.java
.../matrix/database/service/impl/EnvironmentServiceImpl.java
+11
-0
InterfaceInformation.java
...org/matrix/autotest/swaggerData/InterfaceInformation.java
+48
-0
Parameter.java
.../main/java/org/matrix/autotest/swaggerData/Parameter.java
+26
-0
SwaggerController.java
...va/org/matrix/autotest/swaggerData/SwaggerController.java
+50
-21
没有找到文件。
kt-base/src/main/java/org/matrix/database/entity/Environment.java
浏览文件 @
0d4bb98e
...
...
@@ -44,5 +44,8 @@ public class Environment extends BaseEntity {
@ApiModelProperty
(
"ip,例如(http:www.abc.com)"
)
private
String
ip
;
@ApiModelProperty
(
"是否默认"
)
private
Boolean
isDefault
;
}
kt-base/src/main/java/org/matrix/database/service/IEnvironmentService.java
浏览文件 @
0d4bb98e
package
org
.
matrix
.
database
.
service
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.matrix.database.entity.Environment
;
import
com.baomidou.mybatisplus.extension.service.IService
;
...
...
@@ -13,4 +15,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public
interface
IEnvironmentService
extends
IService
<
Environment
>
{
/**
*
* @param isDefault
* @param wrappers
*/
Boolean
setIsDefaultByWrapper
(
Boolean
isDefault
,
Wrapper
wrappers
);
}
kt-base/src/main/java/org/matrix/database/service/impl/EnvironmentServiceImpl.java
浏览文件 @
0d4bb98e
package
org
.
matrix
.
database
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.matrix.database.entity.Environment
;
import
org.matrix.database.mapper.EnvironmentMapper
;
import
org.matrix.database.service.IEnvironmentService
;
import
org.springframework.stereotype.Service
;
import
java.util.Optional
;
/**
* <p>
* 实例表,项目对应的环境实例,例如:实验室环境,开发环境等 服务实现类
...
...
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
@Service
public
class
EnvironmentServiceImpl
extends
ServiceImpl
<
EnvironmentMapper
,
Environment
>
implements
IEnvironmentService
{
@Override
public
Boolean
setIsDefaultByWrapper
(
Boolean
isDefault
,
Wrapper
wrappers
)
{
Environment
environment
=
new
Environment
();
environment
.
setIsDefault
(
isDefault
);
return
Optional
.
of
(
this
.
update
(
environment
,
wrappers
)).
get
();
}
}
kt-web/src/main/java/org/matrix/autotest/swaggerData/InterfaceInformation.java
0 → 100644
浏览文件 @
0d4bb98e
package
org
.
matrix
.
autotest
.
swaggerData
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author mry
*/
@Data
public
class
InterfaceInformation
{
/**
* ip 以及端口信息
*/
private
String
host
;
/**
* /
*/
private
String
basePath
;
/**
* 请求方式
*/
private
String
request
;
/**
* 标签
*/
private
String
tags
;
/**
* 总结
*/
private
String
summary
;
/**
* 方法拼接的url
*/
private
String
methodUrl
;
/**
* 参数
*/
private
List
<
Parameter
>
parameterAllList
;
}
kt-web/src/main/java/org/matrix/autotest/swaggerData/Parameter.java
0 → 100644
浏览文件 @
0d4bb98e
package
org
.
matrix
.
autotest
.
swaggerData
;
import
lombok.Data
;
/**
* @author mry
*/
@Data
public
class
Parameter
{
/**
* 名称
*/
private
String
name
;
/**
* 类型
*/
private
String
type
;
/**
* in
*/
private
String
in
;
}
kt-web/src/main/java/org/matrix/autotest/swaggerData/SwaggerController.java
浏览文件 @
0d4bb98e
package
org
.
matrix
.
autotest
.
swaggerData
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.matrix.database.entity.Environment
;
import
org.matrix.database.service.IEnvironmentService
;
import
org.matrix.exception.GlobalException
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.
Ge
tMapping
;
import
org.springframework.web.bind.annotation.
Pos
tMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -29,6 +34,12 @@ import java.util.Set;
@Api
(
tags
=
"Swagger接口读取与解析"
)
public
class
SwaggerController
{
private
final
IEnvironmentService
service
;
public
SwaggerController
(
IEnvironmentService
service
)
{
this
.
service
=
service
;
}
public
String
loadJson
(
String
url
)
{
BufferedReader
reader
;
StringBuilder
json
=
new
StringBuilder
();
...
...
@@ -43,15 +54,21 @@ public class SwaggerController {
}
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
throw
new
GlobalException
(
"请求swagger数据失败"
);
}
return
json
.
toString
();
}
@GetMapping
public
Object
parameter
(
String
url
)
{
@SuppressWarnings
(
value
=
"all"
)
List
<
String
>
list
=
new
ArrayList
();
@PostMapping
@Transactional
(
rollbackFor
=
Exception
.
class
)
@ApiOperation
(
value
=
"快速添加接口"
)
public
List
<
InterfaceInformation
>
parameter
(
Long
projectId
,
Long
id
)
{
service
.
setIsDefaultByWrapper
(
false
,
Wrappers
.
lambdaQuery
(
Environment
.
class
).
eq
(
Environment:
:
getProjectId
,
projectId
));
service
.
setIsDefaultByWrapper
(
true
,
Wrappers
.
lambdaQuery
(
Environment
.
class
).
eq
(
Environment:
:
getId
,
id
));
Environment
environment
=
service
.
getById
(
id
);
String
url
=
String
.
format
(
"%s/v2/api-docs"
,
environment
.
getIp
());
//获得json字符串
String
json
=
loadJson
(
url
);
JSONObject
swaggerJson
=
JSONObject
.
parseObject
(
json
);
...
...
@@ -65,6 +82,9 @@ public class SwaggerController {
Map
<
String
,
String
>
pathsMaps
=
(
Map
<
String
,
String
>)
paths
;
//获取key
Set
<
String
>
methodUrls
=
pathsMaps
.
keySet
();
List
<
InterfaceInformation
>
list
=
new
ArrayList
<>();
//循环获取每个methodUrl
for
(
String
methodUrl
:
methodUrls
)
{
//将paths转成JSON
...
...
@@ -82,33 +102,42 @@ public class SwaggerController {
Map
<
String
,
String
>
objRequestMaps
=
(
Map
<
String
,
String
>)
objRequest
;
Object
parameters
=
objRequestMaps
.
get
(
"parameters"
);
Object
tags
=
objRequestMaps
.
get
(
"tags"
);
Object
summary
=
objRequestMaps
.
get
(
"summary"
);
List
<
String
>
parameterAllList
=
new
ArrayList
<>();
String
summary
=
objRequestMaps
.
get
(
"summary"
);
List
<
Parameter
>
parameterAllList
=
new
ArrayList
<>();
if
(
parameters
!=
null
)
{
@SuppressWarnings
(
value
=
"all"
)
List
<
String
>
parameterLists
=
(
List
<
String
>)
parameters
;
Parameter
parameter
=
new
Parameter
();
for
(
Object
parameterList
:
parameterLists
)
{
@SuppressWarnings
(
value
=
"unchecked"
)
Map
<
String
,
String
>
parameterMaps
=
(
Map
<
String
,
String
>)
parameterList
;
String
name
=
parameterMaps
.
get
(
"name"
);
String
type
=
parameterMaps
.
get
(
"type"
);
String
in
=
parameterMaps
.
get
(
"in"
);
if
(
name
==
null
)
{
name
=
""
;
}
if
(
type
==
null
)
{
type
=
""
;
}
if
(
in
==
null
)
{
in
=
""
;
}
parameterAllList
.
add
(
"name="
+
name
+
" type="
+
type
+
" in="
+
in
);
parameter
.
setIn
(
in
);
parameter
.
setName
(
name
);
parameter
.
setType
(
type
);
parameterAllList
.
add
(
parameter
);
}
}
list
.
add
(
"{host="
+
host
+
", basePath="
+
basePath
+
", request="
+
request
+
", name="
+
tags
+
"-"
+
summary
+
", methodUrl="
+
methodUrl
+
", parameters="
+
parameterAllList
+
"}"
);
InterfaceInformation
interfaceInformation
=
new
InterfaceInformation
();
interfaceInformation
.
setHost
(
String
.
valueOf
(
host
));
interfaceInformation
.
setParameterAllList
(
parameterAllList
);
interfaceInformation
.
setBasePath
(
String
.
valueOf
(
basePath
));
interfaceInformation
.
setRequest
(
request
);
interfaceInformation
.
setSummary
(
summary
);
interfaceInformation
.
setMethodUrl
(
methodUrl
);
interfaceInformation
.
setTags
(
String
.
valueOf
(
tags
));
list
.
add
(
interfaceInformation
);
}
}
return
JSON
.
toJSON
(
list
)
;
return
list
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论