fix(接口测试): swagger 导入报错
This commit is contained in:
parent
7b0045d1a7
commit
cd42469860
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue