fix(接口测试): swagger 导入报错

This commit is contained in:
chenjianxing 2020-09-17 19:37:28 +08:00
parent 7b0045d1a7
commit cd42469860
1 changed files with 25 additions and 23 deletions

View File

@ -159,32 +159,34 @@ public class Swagger2Parser extends ApiImportAbstractParser {
private JSONObject getBodyJSONObjectParameters(Map<String, Property> properties, Map<String, Model> definitions, HashSet<String> refSet) {
JSONObject jsonObject = new JSONObject();
properties.forEach((key, value) -> {
if (value instanceof ObjectProperty) {
ObjectProperty objectProperty = (ObjectProperty) value;
jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions, refSet));
} else if (value instanceof ArrayProperty) {
ArrayProperty arrayProperty = (ArrayProperty) value;
Property items = arrayProperty.getItems();
if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items;
String simpleRef = refProperty.getSimpleRef();
if (refSet.contains(simpleRef)) {
jsonObject.put(key, new JSONArray());
return;
if (properties != null) {
properties.forEach((key, value) -> {
if (value instanceof ObjectProperty) {
ObjectProperty objectProperty = (ObjectProperty) value;
jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions, refSet));
} else if (value instanceof ArrayProperty) {
ArrayProperty arrayProperty = (ArrayProperty) value;
Property items = arrayProperty.getItems();
if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items;
String simpleRef = refProperty.getSimpleRef();
if (refSet.contains(simpleRef)) {
jsonObject.put(key, new JSONArray());
return;
}
refSet.add(simpleRef);
Model model = definitions.get(simpleRef);
JSONArray propertyList = new JSONArray();
propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions, refSet));
jsonObject.put(key, propertyList);
} else {
jsonObject.put(key, new ArrayList<>());
}
refSet.add(simpleRef);
Model model = definitions.get(simpleRef);
JSONArray propertyList = new JSONArray();
propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions, refSet));
jsonObject.put(key, propertyList);
} else {
jsonObject.put(key, new ArrayList<>());
jsonObject.put(key, Optional.ofNullable(value.getDescription()).orElse(""));
}
} else {
jsonObject.put(key, Optional.ofNullable(value.getDescription()).orElse(""));
}
});
});
}
return jsonObject;
}