feat(接口自动化): 增加外部导入到场景功能
This commit is contained in:
parent
86c6254d48
commit
a73b202551
|
@ -32,7 +32,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
if (testObject.get("projectName") != null) {
|
||||
return parseMsFormat(testStr, request);
|
||||
} else {
|
||||
return parsePluginFormat(testObject);
|
||||
return parsePluginFormat(testObject, request.isSaved());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,14 +53,16 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
return apiDefinitionImport;
|
||||
}
|
||||
|
||||
private ApiDefinitionImport parsePluginFormat(JSONObject testObject) {
|
||||
private ApiDefinitionImport parsePluginFormat(JSONObject testObject, boolean isSaved) {
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
apiImport.setProtocol(RequestType.HTTP);
|
||||
apiImport.setData(results);
|
||||
testObject.keySet().forEach(tag -> {
|
||||
ApiModule module = apiModuleService.getNewModule(tag, this.projectId, 1);
|
||||
if (isSaved) {
|
||||
createModule(module);
|
||||
}
|
||||
JSONObject requests = testObject.getJSONObject(tag);
|
||||
requests.keySet().forEach(requestName -> {
|
||||
|
||||
|
|
|
@ -30,17 +30,17 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
parseItem(postmanCollection.getItem(), variables, results, buildModule(postmanCollection.getInfo().getName(), null));
|
||||
parseItem(postmanCollection.getItem(), variables, results, buildModule(postmanCollection.getInfo().getName(), null, request.isSaved()), request.isSaved());
|
||||
apiImport.setData(results);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionResult> results, ApiModule parentModule) {
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionResult> results, ApiModule parentModule, boolean isSaved) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
ApiModule module = buildModule(item.getName(), parentModule);
|
||||
parseItem(childItems, variables, results, module);
|
||||
ApiModule module = buildModule(item.getName(), parentModule, isSaved);
|
||||
parseItem(childItems, variables, results, module, isSaved);
|
||||
} else {
|
||||
ApiDefinitionResult request = parsePostman(item);
|
||||
if (request != null) {
|
||||
|
@ -53,7 +53,7 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiModule buildModule(String name, ApiModule parentModule) {
|
||||
private ApiModule buildModule(String name, ApiModule parentModule, boolean isSaved) {
|
||||
apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
|
||||
ApiModule module;
|
||||
if (parentModule != null) {
|
||||
|
@ -62,7 +62,9 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
} else {
|
||||
module = apiModuleService.getNewModule(name, this.projectId, 1);
|
||||
}
|
||||
if (isSaved) {
|
||||
createModule(module);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
}
|
||||
ApiDefinitionImport definitionImport = new ApiDefinitionImport();
|
||||
this.projectId = request.getProjectId();
|
||||
definitionImport.setData(parseRequests(swagger));
|
||||
definitionImport.setData(parseRequests(swagger, request.isSaved()));
|
||||
return definitionImport;
|
||||
}
|
||||
|
||||
private List<ApiDefinitionResult> parseRequests(Swagger swagger) {
|
||||
private List<ApiDefinitionResult> parseRequests(Swagger swagger, boolean isSaved) {
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
Set<String> pathNames = paths.keySet();
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
parseParameters(operation, request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses())));
|
||||
buildModule(apiDefinition, operation);
|
||||
buildModule(apiDefinition, operation, isSaved);
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
|
@ -71,13 +71,15 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
return results;
|
||||
}
|
||||
|
||||
private void buildModule(ApiDefinitionResult apiDefinition, Operation operation) {
|
||||
private void buildModule(ApiDefinitionResult apiDefinition, Operation operation, boolean isSaved) {
|
||||
List<String> tags = operation.getTags();
|
||||
if (tags != null) {
|
||||
tags.forEach(tag -> {
|
||||
apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
|
||||
ApiModule module = apiModuleService.getNewModule(tag, this.projectId, 1);
|
||||
if (isSaved) {
|
||||
createModule(module);
|
||||
}
|
||||
apiDefinition.setModuleId(module.getId());
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue