fix(接口测试): 解决swagger导入部分属性处理问题

--user=郭雨琦
--bug=1012975
[接口测试]github#13228swagger2.0导入接口的请求参数键值均为string类型的map字典,导入MS后在请求参数中缺少这个map
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001012975
This commit is contained in:
guoyuqi 2022-05-05 16:58:28 +08:00 committed by fit2-zhao
parent ced328afce
commit 8cacdad6c0
4 changed files with 14 additions and 2 deletions

View File

@ -303,6 +303,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
item.setType("object"); item.setType("object");
ModelImpl model = (ModelImpl) schema; ModelImpl model = (ModelImpl) schema;
item.setProperties(parseNewSchemaProperties(model, refSet)); item.setProperties(parseNewSchemaProperties(model, refSet));
if(model.getAdditionalProperties()!=null){
item.setAdditionalProperties(parseProperty(model.getAdditionalProperties(), refSet));
}
} else if (schema instanceof AbstractModel) { } else if (schema instanceof AbstractModel) {
AbstractModel abstractModel = (AbstractModel) schema; AbstractModel abstractModel = (AbstractModel) schema;
item.setType("object"); item.setType("object");
@ -404,6 +407,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
if(model.getRequired()!=null){ if(model.getRequired()!=null){
item.setRequired(model.getRequired()); item.setRequired(model.getRequired());
} }
if(model.getAdditionalProperties()!=null){
item.setAdditionalProperties(parseProperty(model.getAdditionalProperties(), new HashSet<>()));
}
} }
}else if(schema instanceof AbstractModel){ }else if(schema instanceof AbstractModel){
AbstractModel abstractModel = (AbstractModel) schema; AbstractModel abstractModel = (AbstractModel) schema;

View File

@ -21,6 +21,7 @@ public class JsonSchemaItem {
private List<JsonSchemaItem> items; private List<JsonSchemaItem> items;
private Map<String, Object> mock; private Map<String, Object> mock;
private Map<String, JsonSchemaItem> properties; private Map<String, JsonSchemaItem> properties;
private JsonSchemaItem additionalProperties;
private List<String> required ; private List<String> required ;
@JSONField(name = "$schema") @JSONField(name = "$schema")

View File

@ -4,6 +4,7 @@ public class BasicConstant {
public final static String REQUIRED = "required"; public final static String REQUIRED = "required";
public final static String ALL_OF = "allOf"; public final static String ALL_OF = "allOf";
public final static String PROPERTIES = "properties"; public final static String PROPERTIES = "properties";
public final static String ADDITIONAL_PROPERTIES = "additionalProperties";
public final static String TYPE = "type"; public final static String TYPE = "type";
public final static String MS_OBJECT = "MS-OBJECT"; public final static String MS_OBJECT = "MS-OBJECT";
public final static String ARRAY = "array"; public final static String ARRAY = "array";

View File

@ -54,7 +54,11 @@ public class JSONSchemaGenerator {
JsonObject propertyObj = propertiesObj.get(propertyKey).getAsJsonObject(); JsonObject propertyObj = propertiesObj.get(propertyKey).getAsJsonObject();
analyzeProperty(rootObj, propertyKey, propertyObj); analyzeProperty(rootObj, propertyKey, propertyObj);
} }
} else if (object.has(BasicConstant.TYPE) && object.get(BasicConstant.TYPE).getAsString().equals(BasicConstant.ARRAY)) { }else if (object.has(BasicConstant.ADDITIONAL_PROPERTIES)) {
JsonObject propertiesObj = object.get(BasicConstant.ADDITIONAL_PROPERTIES).getAsJsonObject();
analyzeProperty(rootObj, BasicConstant.ADDITIONAL_PROPERTIES, propertiesObj);
}
else if (object.has(BasicConstant.TYPE) && object.get(BasicConstant.TYPE).getAsString().equals(BasicConstant.ARRAY)) {
analyzeProperty(rootObj, BasicConstant.MS_OBJECT, object); analyzeProperty(rootObj, BasicConstant.MS_OBJECT, object);
} else if (object.has(BasicConstant.TYPE) && !object.get(BasicConstant.TYPE).getAsString().equals(BasicConstant.OBJECT)) { } else if (object.has(BasicConstant.TYPE) && !object.get(BasicConstant.TYPE).getAsString().equals(BasicConstant.OBJECT)) {
analyzeProperty(rootObj, object.getAsString(), object); analyzeProperty(rootObj, object.getAsString(), object);
@ -94,7 +98,7 @@ public class JSONSchemaGenerator {
} }
} else if (propertyObjType.equals(BasicConstant.STRING)) { } else if (propertyObjType.equals(BasicConstant.STRING)) {
// 先设置空值 // 先设置空值
concept.put(propertyName, ""); concept.put(propertyName,"");
if (object.has("format")) { if (object.has("format")) {
String propertyFormat = object.get("format").getAsString(); String propertyFormat = object.get("format").getAsString();
if (propertyFormat.equals("date-time")) { if (propertyFormat.equals("date-time")) {