fix(接口测试): json-schema数组类型解析有误

This commit is contained in:
AgAngle 2024-07-04 16:56:59 +08:00 committed by jianxing
parent e1c38e87d4
commit 54c102aad3
3 changed files with 13 additions and 8 deletions

View File

@ -51,7 +51,7 @@ public class JsonSchemaItem {
* type 为array 使用该值 * type 为array 使用该值
*/ */
@Valid @Valid
private JsonSchemaItem items; private List<JsonSchemaItem> items;
/** /**
* 参数属性 * 参数属性
* type object 使用该值 * type object 使用该值
@ -126,7 +126,7 @@ public class JsonSchemaItem {
if (type.equals(PropertyConstant.OBJECT)) { if (type.equals(PropertyConstant.OBJECT)) {
this.properties = new LinkedHashMap<>(); this.properties = new LinkedHashMap<>();
} else if (type.equals(PropertyConstant.ARRAY)) { } else if (type.equals(PropertyConstant.ARRAY)) {
this.items = new JsonSchemaItem(); this.items = List.of();
} }
} }

View File

@ -577,7 +577,7 @@ public class Swagger3Parser extends ApiImportAbstractParser<ApiDefinitionImport>
JsonSchemaItem arrayItem = new JsonSchemaItem(); JsonSchemaItem arrayItem = new JsonSchemaItem();
arrayItem.setId(IDGenerator.nextStr()); arrayItem.setId(IDGenerator.nextStr());
arrayItem.setType(PropertyConstant.ARRAY); arrayItem.setType(PropertyConstant.ARRAY);
arrayItem.setItems(new JsonSchemaItem()); arrayItem.setItems(List.of());
yield arrayItem; yield arrayItem;
} }
yield isRef(arraySchema.getItems(), 0) ? parseArraySchema(arraySchema, true) : yield isRef(arraySchema.getItems(), 0) ? parseArraySchema(arraySchema, true) :
@ -712,7 +712,7 @@ public class Swagger3Parser extends ApiImportAbstractParser<ApiDefinitionImport>
} }
JsonSchemaItem itemsJsonSchema = parseProperty(itemsSchema, onlyOnce); JsonSchemaItem itemsJsonSchema = parseProperty(itemsSchema, onlyOnce);
jsonSchemaArray.setItems(itemsJsonSchema); jsonSchemaArray.setItems(List.of(itemsJsonSchema));
jsonSchemaArray.setMaxItems(arraySchema.getMaxItems()); jsonSchemaArray.setMaxItems(arraySchema.getMaxItems());
jsonSchemaArray.setMinItems(arraySchema.getMinItems()); jsonSchemaArray.setMinItems(arraySchema.getMinItems());
return jsonSchemaArray; return jsonSchemaArray;

View File

@ -772,12 +772,17 @@ public class ApiDefinitionImportService {
} }
} }
if (jsonSchema != null && StringUtils.equals(jsonSchema.getType(), PropertyConstant.ARRAY)) { if (jsonSchema != null && StringUtils.equals(jsonSchema.getType(), PropertyConstant.ARRAY)) {
JsonSchemaItem items = jsonSchema.getItems(); List<JsonSchemaItem> jsonSchemaItems = jsonSchema.getItems();
JsonSchemaItem importItems = importJsonSchema.getItems(); List<JsonSchemaItem> importJsonSchemaItems = importJsonSchema.getItems();
if (items != null && importItems != null) { if (jsonSchemaItems != null && importJsonSchemaItems != null) {
if (!jsonSchemaIsSame(items, importItems)) { if (jsonSchemaItems.size() != importJsonSchemaItems.size()) {
return false; return false;
} }
for (int i = 0; i < jsonSchemaItems.size(); i++) {
if (!jsonSchemaIsSame(jsonSchemaItems.get(i), importJsonSchemaItems.get(i))) {
return false;
}
}
} }
} }
return same; return same;