fix(接口测试): 解决swagger导入问题

--user=郭雨琦
--bug=1013871
https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001013871
swagger导入有文件传不上来,有的文件导入后响应体展示的数据不对
This commit is contained in:
guoyuqi 2022-06-16 18:39:54 +08:00 committed by 刘瑞斌
parent d43be9bc35
commit 40609eb8f9
2 changed files with 52 additions and 55 deletions

View File

@ -24,7 +24,6 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.InputStream;
import java.util.*;
@ -48,7 +47,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
} else {
sourceStr = getApiTestStr(source); // 导入的二进制文件转换为 String
swagger = new SwaggerParser().readWithInfo(sourceStr).getSwagger();
swagger = new SwaggerParser().readWithInfo(sourceStr, false).getSwagger();
}
if (swagger == null || swagger.getSwagger() == null) { // 不是 2.0 版本则尝试转换 3.0
Swagger3Parser swagger3Parser = new Swagger3Parser();
@ -612,8 +611,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
propertyList.add(getBodyParameters(((ObjectProperty) items).getProperties(), refSet));
}
jsonObject.put(key, propertyList);
}
else {
} else {
jsonObject.put(key, new ArrayList<>());
}
} else if (value instanceof RefProperty) {

View File

@ -122,7 +122,6 @@ public class Swagger3Parser extends SwaggerAbstractParser {
}
private List<ApiDefinitionWithBLOBs> parseRequests(OpenAPI openAPI, ApiTestImportRequest importRequest) {
Paths paths = openAPI.getPaths();
@ -380,7 +379,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
Object propertiesResult = parseSchemaPropertiesToJson(schema, refSet, infoMap);
return propertiesResult == null ? getDefaultValueByPropertyType(schema) : propertiesResult;
} else {
return schema;
return getDefaultValueByPropertyType(schema);
}
}
@ -525,7 +524,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
return example == null ? 0 : example;
} else if (value instanceof NumberSchema) {
return example == null ? 0.0 : example;
} else if (value instanceof StringSchema) {
} else if (value instanceof StringSchema || value.getType().equals("string")) {
return example == null ? "" : example;
} else {// todo 其他类型?
return getDefaultStringValue(value.getDescription());