fix(接口测试): 解决swagger导入问题
--user=郭雨琦 --bug=1013871 https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001013871 swagger导入有文件传不上来,有的文件导入后响应体展示的数据不对
This commit is contained in:
parent
d43be9bc35
commit
40609eb8f9
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue