fix(数据源): 解析API数据源出错

This commit is contained in:
taojinlong 2022-11-02 17:20:15 +08:00
parent 2a0087c0db
commit ffba26de67

View File

@ -34,6 +34,8 @@ import java.util.stream.Collectors;
@Service("apiProvider") @Service("apiProvider")
public class ApiProvider extends Provider { public class ApiProvider extends Provider {
private static String path = "['%s']";
@Resource @Resource
private SystemParameterService systemParameterService; private SystemParameterService systemParameterService;
@ -198,10 +200,10 @@ public class ApiProvider extends Provider {
handleStr(apiDefinition, response, fields, rootPath); handleStr(apiDefinition, response, fields, rootPath);
} }
for (JSONObject field : fields) { for (JSONObject field : fields) {
if(field.containsKey("children") && CollectionUtils.isNotEmpty(field.getJSONArray("children"))){ if (field.containsKey("children") && CollectionUtils.isNotEmpty(field.getJSONArray("children"))) {
field.put("disabled", false); field.put("disabled", false);
} }
if(field.containsKey("children") && CollectionUtils.isEmpty(field.getJSONArray("children"))){ if (field.containsKey("children") && CollectionUtils.isEmpty(field.getJSONArray("children"))) {
field.put("disabled", true); field.put("disabled", true);
} }
} }
@ -238,14 +240,14 @@ public class ApiProvider extends Provider {
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : ""); array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
o.put("value", array); o.put("value", array);
} }
o.put("jsonPath", rootPath + "." + s); o.put("jsonPath", rootPath + "." + String.format(path, s));
setProperty(apiDefinition, o, s); setProperty(apiDefinition, o, s);
if (!hasItem(apiDefinition, fields, o)) { if (!hasItem(apiDefinition, fields, o)) {
fields.add(o); fields.add(o);
} }
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) { } else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
List<JSONObject> children = new ArrayList<>(); List<JSONObject> children = new ArrayList<>();
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + s); handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
o.put("children", children); o.put("children", children);
o.put("childrenDataType", "OBJECT"); o.put("childrenDataType", "OBJECT");
@ -256,7 +258,7 @@ public class ApiProvider extends Provider {
} }
} else { } else {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
o.put("jsonPath", rootPath + "." + s); o.put("jsonPath", rootPath + "." + String.format(path, s));
setProperty(apiDefinition, o, s); setProperty(apiDefinition, o, s);
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : ""); array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");