fix(接口测试): 修复swagger特殊数据导入失败的缺陷

--bug=1029400 --user=王孝刚
【接口测试】github#26329,swagger文件(18mb)导入报错,info.log提示property为空
https://www.tapd.cn/55049933/s/1409241
This commit is contained in:
wxg0103 2023-08-29 10:03:11 +08:00 committed by fit2-zhao
parent 983faa8168
commit 47440d78b9
1 changed files with 5 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import io.swagger.models.properties.*;
import io.swagger.parser.SwaggerParser;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -392,13 +393,11 @@ public class Swagger2Parser extends SwaggerAbstractParser {
private JsonSchemaItem parseProperty(Property property, HashSet<String> refSet) {
JsonSchemaItem item = new JsonSchemaItem();
item.setDescription(property.getDescription());
if (property instanceof ObjectProperty) {
ObjectProperty objectProperty = (ObjectProperty) property;
item.setDescription(ObjectUtils.isNotEmpty(property) ? property.getDescription() : StringUtils.EMPTY);
if (property instanceof ObjectProperty objectProperty) {
item.setType(PropertyConstant.OBJECT);
item.setProperties(parseSchemaProperties(objectProperty.getProperties(), refSet));
} else if (property instanceof ArrayProperty) {
ArrayProperty arrayProperty = (ArrayProperty) property;
} else if (property instanceof ArrayProperty arrayProperty) {
handleArrayItemProperties(item, arrayProperty.getItems(), refSet);
} else if (property instanceof RefProperty) {
item.setType(PropertyConstant.OBJECT);
@ -406,7 +405,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
} else {
handleBaseProperties(item, property);
}
if (property.getExample() != null) {
if (ObjectUtils.isNotEmpty(property) && property.getExample() != null) {
item.getMock().put(PropertyConstant.MOCK, property.getExample());
} else {
item.getMock().put(PropertyConstant.MOCK, StringUtils.EMPTY);