fix: 接口导入覆盖标签

This commit is contained in:
chenjianxing 2021-11-16 11:25:47 +08:00 committed by jianxing
parent a309c4dfc4
commit 230c0d4c30
3 changed files with 21 additions and 16 deletions

View File

@ -297,21 +297,26 @@ public class Swagger3Parser extends SwaggerAbstractParser {
private void parseKvBody(Schema schema, Body body, Object data, Map<String, Schema> infoMap) {
if (data instanceof JSONObject) {
((JSONObject) data).forEach((k, v) -> {
Schema dataSchema = (Schema) v;
KeyValue kv = new KeyValue(k, String.valueOf(dataSchema.getExample()), dataSchema.getDescription());
Schema schemaInfo = infoMap.get(k);
if (schemaInfo != null) {
if (schemaInfo instanceof BinarySchema) {
kv.setType("file");
if (v != null && v instanceof Schema) {
Schema dataSchema = (Schema) v;
KeyValue kv = new KeyValue(k, String.valueOf(dataSchema.getExample()), dataSchema.getDescription());
Schema schemaInfo = infoMap.get(k);
if (schemaInfo != null) {
if (schemaInfo instanceof BinarySchema) {
kv.setType("file");
}
}
if (body.getKvs() == null) { // 防止空指针
body.setKvs(new ArrayList<>());
}
body.getKvs().add(kv);
}
if (body.getKvs() == null) { // 防止空指针
body.setKvs(new ArrayList<>());
}
body.getKvs().add(kv);
});
} else {
if(data instanceof Schema) {
if (data instanceof String && StringUtils.isBlank((String)data)) {
return;
}
Schema dataSchema = (Schema) data;
KeyValue kv = new KeyValue(schema.getName(), String.valueOf(dataSchema.getExample()), schema.getDescription());
Schema schemaInfo = infoMap.get(schema.getName());

View File

@ -680,13 +680,14 @@ public class ApiDefinitionService {
apiDefinition.setStatus(sameRequest.get(0).getStatus());
apiDefinition.setOriginalState(sameRequest.get(0).getOriginalState());
apiDefinition.setCaseStatus(sameRequest.get(0).getCaseStatus());
apiDefinition.setNum(sameRequest.get(0).getNum()); //id 不变
apiDefinition.setTags(sameRequest.get(0).getTags()); //tag 不变
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
//如果存在则修改
apiDefinition.setId(sameRequest.get(0).getId());
String request = setImportHashTree(apiDefinition);
apiDefinition.setModuleId(sameRequest.get(0).getModuleId());
apiDefinition.setModulePath(sameRequest.get(0).getModulePath());
apiDefinition.setNum(sameRequest.get(0).getNum()); //id 不变
apiDefinition.setOrder(sameRequest.get(0).getOrder());
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
apiDefinition.setRequest(request);

View File

@ -2,8 +2,6 @@ package io.metersphere.commons.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
@ -15,12 +13,13 @@ public class XMLUtils {
Set<Map.Entry<String, Object>> se = jObj.entrySet();
StringBuffer nowTab = new StringBuffer(tab.toString());
for (Map.Entry<String, Object> en : se) {
if ("com.alibaba.fastjson.JSONObject".equals(en.getValue().getClass().getName())) {
if (en == null || en.getValue() == null) continue;
if (en.getValue() instanceof JSONObject) {
buffer.append(tab).append("<").append(en.getKey()).append(">\n");
JSONObject jo = jObj.getJSONObject(en.getKey());
jsonToXmlStr(jo, buffer, nowTab.append("\t"));
buffer.append(tab).append("</").append(en.getKey()).append(">\n");
} else if ("com.alibaba.fastjson.JSONArray".equals(en.getValue().getClass().getName())) {
} else if (en.getValue() instanceof JSONArray) {
JSONArray jarray = jObj.getJSONArray(en.getKey());
for (int i = 0; i < jarray.size(); i++) {
buffer.append(tab).append("<").append(en.getKey()).append(">\n");
@ -30,7 +29,7 @@ public class XMLUtils {
buffer.append(tab).append("</").append(en.getKey()).append(">\n");
}
}
} else if ("java.lang.String".equals(en.getValue().getClass().getName())) {
} else if (en.getValue() instanceof String) {
buffer.append(tab).append("<").append(en.getKey()).append(">").append(en.getValue());
buffer.append("</").append(en.getKey()).append(">\n");
}