Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
2f4561f7
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 3 年多
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2f4561f7
编写于
7月 29, 2020
作者:
C
Captain.B
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/v1.1' into v1.1
上级
999dc865
df7865bc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
28 deletion
+48
-28
backend/src/main/java/io/metersphere/api/dto/parse/postman/PostmanCollection.java
.../metersphere/api/dto/parse/postman/PostmanCollection.java
+1
-1
backend/src/main/java/io/metersphere/api/dto/parse/postman/PostmanItem.java
...ava/io/metersphere/api/dto/parse/postman/PostmanItem.java
+3
-1
backend/src/main/java/io/metersphere/api/parse/PostmanParser.java
...src/main/java/io/metersphere/api/parse/PostmanParser.java
+42
-24
frontend/src/business/components/api/test/components/import/ApiImport.vue
...iness/components/api/test/components/import/ApiImport.vue
+2
-2
未找到文件。
backend/src/main/java/io/metersphere/api/dto/parse/postman/PostmanCollection.java
浏览文件 @
2f4561f7
...
...
@@ -8,6 +8,6 @@ import java.util.List;
public
class
PostmanCollection
{
private
PostmanCollectionInfo
info
;
private
List
<
PostmanItem
>
item
;
private
List
<
PostmanKeyValue
>
variable
;
}
backend/src/main/java/io/metersphere/api/dto/parse/postman/PostmanItem.java
浏览文件 @
2f4561f7
...
...
@@ -2,9 +2,11 @@ package io.metersphere.api.dto.parse.postman;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
PostmanItem
{
private
String
name
;
private
PostmanRequest
request
;
private
List
<
PostmanItem
>
item
;
}
backend/src/main/java/io/metersphere/api/parse/PostmanParser.java
浏览文件 @
2f4561f7
...
...
@@ -15,10 +15,7 @@ import io.metersphere.commons.constants.PostmanRequestBodyMode;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
public
class
PostmanParser
extends
ApiImportAbstractParser
{
...
...
@@ -35,18 +32,20 @@ public class PostmanParser extends ApiImportAbstractParser {
@Override
public
ApiImport
parse
(
InputStream
source
,
ApiTestImportRequest
request
)
{
String
testStr
=
getApiTestStr
(
source
);
PostmanCollection
postmanCollection
=
JSON
.
parseObject
(
testStr
,
PostmanCollection
.
class
);
PostmanCollectionInfo
info
=
postmanCollection
.
getInfo
();
List
<
Request
>
requests
=
parseRequests
(
postmanCollection
);
List
<
PostmanKeyValue
>
variables
=
postmanCollection
.
getVariable
(
);
ApiImport
apiImport
=
new
ApiImport
();
List
<
Scenario
>
scenarios
=
new
ArrayList
<>();
Scenario
scenario
=
new
Scenario
();
scenario
.
setRequests
(
requests
);
scenario
.
setName
(
info
.
getName
());
setScenarioByRequest
(
scenario
,
request
);
scenarios
.
add
(
scenario
);
parseItem
(
postmanCollection
.
getItem
(),
scenario
,
variables
,
scenarios
);
apiImport
.
setScenarios
(
scenarios
);
return
apiImport
;
}
...
...
@@ -59,23 +58,42 @@ public class PostmanParser extends ApiImportAbstractParser {
return
keyValues
;
}
private
List
<
Request
>
parseRequests
(
PostmanCollection
postmanCollection
)
{
List
<
PostmanItem
>
item
=
postmanCollection
.
getItem
();
private
void
parseItem
(
List
<
PostmanItem
>
items
,
Scenario
scenario
,
List
<
PostmanKeyValue
>
variables
,
List
<
Scenario
>
scenarios
)
{
List
<
Request
>
requests
=
new
ArrayList
<>();
for
(
PostmanItem
requestItem
:
item
)
{
HttpRequest
request
=
new
HttpRequest
();
PostmanRequest
requestDesc
=
requestItem
.
getRequest
();
PostmanUrl
url
=
requestDesc
.
getUrl
();
request
.
setName
(
requestItem
.
getName
());
request
.
setUrl
(
url
.
getRaw
());
request
.
setUseEnvironment
(
false
);
request
.
setMethod
(
requestDesc
.
getMethod
());
request
.
setHeaders
(
parseKeyValue
(
requestDesc
.
getHeader
()));
request
.
setParameters
(
parseKeyValue
(
url
.
getQuery
()));
request
.
setBody
(
parseBody
(
requestDesc
,
request
));
requests
.
add
(
request
);
for
(
PostmanItem
item
:
items
)
{
List
<
PostmanItem
>
childItems
=
item
.
getItem
();
if
(
childItems
!=
null
)
{
Scenario
subScenario
=
new
Scenario
();
subScenario
.
setName
(
item
.
getName
());
subScenario
.
setEnvironmentId
(
scenario
.
getEnvironmentId
());
parseItem
(
childItems
,
subScenario
,
variables
,
scenarios
);
}
else
{
Request
request
=
parseRequest
(
item
);
if
(
request
!=
null
)
{
requests
.
add
(
request
);
}
}
}
scenario
.
setVariables
(
parseKeyValue
(
variables
));
scenario
.
setRequests
(
requests
);
scenarios
.
add
(
scenario
);
}
private
Request
parseRequest
(
PostmanItem
requestItem
)
{
HttpRequest
request
=
new
HttpRequest
();
PostmanRequest
requestDesc
=
requestItem
.
getRequest
();
if
(
requestDesc
==
null
)
{
return
null
;
}
return
requests
;
PostmanUrl
url
=
requestDesc
.
getUrl
();
request
.
setName
(
requestItem
.
getName
());
request
.
setUrl
(
url
.
getRaw
());
request
.
setUseEnvironment
(
false
);
request
.
setMethod
(
requestDesc
.
getMethod
());
request
.
setHeaders
(
parseKeyValue
(
requestDesc
.
getHeader
()));
request
.
setParameters
(
parseKeyValue
(
url
.
getQuery
()));
request
.
setBody
(
parseBody
(
requestDesc
,
request
));
return
request
;
}
private
Body
parseBody
(
PostmanRequest
requestDesc
,
HttpRequest
request
)
{
...
...
@@ -88,8 +106,8 @@ public class PostmanParser extends ApiImportAbstractParser {
if
(
StringUtils
.
equals
(
bodyMode
,
PostmanRequestBodyMode
.
RAW
.
value
()))
{
body
.
setRaw
(
postmanBody
.
getString
(
bodyMode
));
body
.
setType
(
MsRequestBodyType
.
RAW
.
value
());
String
contentType
=
postmanBodyRowMap
.
get
(
postmanBody
.
getJSONObject
(
"options"
).
getJSONObject
(
"raw"
).
getString
(
"language"
)
);
addContentType
(
request
,
contentTyp
e
);
String
language
=
postmanBody
.
getJSONObject
(
"options"
).
getJSONObject
(
PostmanRequestBodyMode
.
RAW
.
value
()).
getString
(
"language"
);
body
.
setFormat
(
languag
e
);
}
else
if
(
StringUtils
.
equals
(
bodyMode
,
PostmanRequestBodyMode
.
FORM_DATA
.
value
())
||
StringUtils
.
equals
(
bodyMode
,
PostmanRequestBodyMode
.
URLENCODED
.
value
()))
{
List
<
PostmanKeyValue
>
postmanKeyValues
=
JSON
.
parseArray
(
postmanBody
.
getString
(
bodyMode
),
PostmanKeyValue
.
class
);
body
.
setType
(
MsRequestBodyType
.
KV
.
value
());
...
...
frontend/src/business/components/api/test/components/import/ApiImport.vue
浏览文件 @
2f4561f7
...
...
@@ -28,7 +28,7 @@
<el-option
v-for=
"(project, index) in projects"
:key=
"index"
:label=
"project.name"
:value=
"project.id"
/>
</el-select>
</el-form-item>
<el-form-item
v-if=
"
(selectedPlatformValue != 'Postman' && useEnvironment)
|| selectedPlatformValue == 'Swagger2'"
:label=
"$t('api_test.environment.environment_config')"
prop=
"environmentId"
>
<el-form-item
v-if=
"
useEnvironment
|| selectedPlatformValue == 'Swagger2'"
:label=
"$t('api_test.environment.environment_config')"
prop=
"environmentId"
>
<el-select
v-if=
"showEnvironmentSelect"
size=
"small"
v-model=
"formData.environmentId"
class=
"environment-select"
clearable
>
<el-option
v-for=
"(environment, index) in environments"
:key=
"index"
:label=
"environment.name + ': ' + environment.protocol + '://' + environment.socket"
:value=
"environment.id"
/>
<el-button
class=
"environment-button"
size=
"mini"
type=
"primary"
@
click=
"openEnvironmentConfig"
>
{{
$t
(
'
api_test.environment.environment_config
'
)
}}
</el-button>
...
...
@@ -39,7 +39,7 @@
</
template
>
</el-select>
</el-form-item>
<el-form-item
v-if=
"selectedPlatformValue
== 'Metersphere
'"
prop=
"useEnvironment"
>
<el-form-item
v-if=
"selectedPlatformValue
!= 'Swagger2
'"
prop=
"useEnvironment"
>
<el-checkbox
v-model=
"useEnvironment"
>
{{$t('api_test.environment.config_environment')}}
</el-checkbox>
</el-form-item>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录