diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java index b39b21f9f8..9f908b9ddb 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java @@ -303,6 +303,9 @@ public class Swagger2Parser extends SwaggerAbstractParser { item.setType("object"); ModelImpl model = (ModelImpl) schema; item.setProperties(parseNewSchemaProperties(model, refSet)); + if(model.getAdditionalProperties()!=null){ + item.setAdditionalProperties(parseProperty(model.getAdditionalProperties(), refSet)); + } } else if (schema instanceof AbstractModel) { AbstractModel abstractModel = (AbstractModel) schema; item.setType("object"); @@ -404,6 +407,9 @@ public class Swagger2Parser extends SwaggerAbstractParser { if(model.getRequired()!=null){ item.setRequired(model.getRequired()); } + if(model.getAdditionalProperties()!=null){ + item.setAdditionalProperties(parseProperty(model.getAdditionalProperties(), new HashSet<>())); + } } }else if(schema instanceof AbstractModel){ AbstractModel abstractModel = (AbstractModel) schema; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java index d31dbc1930..103c5772fe 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java @@ -21,6 +21,7 @@ public class JsonSchemaItem { private List items; private Map mock; private Map properties; + private JsonSchemaItem additionalProperties; private List required ; @JSONField(name = "$schema") diff --git a/backend/src/main/java/io/metersphere/commons/json/BasicConstant.java b/backend/src/main/java/io/metersphere/commons/json/BasicConstant.java index a76bf2f732..2e36db7e8a 100644 --- a/backend/src/main/java/io/metersphere/commons/json/BasicConstant.java +++ b/backend/src/main/java/io/metersphere/commons/json/BasicConstant.java @@ -4,6 +4,7 @@ public class BasicConstant { public final static String REQUIRED = "required"; public final static String ALL_OF = "allOf"; public final static String PROPERTIES = "properties"; + public final static String ADDITIONAL_PROPERTIES = "additionalProperties"; public final static String TYPE = "type"; public final static String MS_OBJECT = "MS-OBJECT"; public final static String ARRAY = "array"; diff --git a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java index f17cf7f917..5519f73962 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java @@ -54,7 +54,11 @@ public class JSONSchemaGenerator { JsonObject propertyObj = propertiesObj.get(propertyKey).getAsJsonObject(); 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); } else if (object.has(BasicConstant.TYPE) && !object.get(BasicConstant.TYPE).getAsString().equals(BasicConstant.OBJECT)) { analyzeProperty(rootObj, object.getAsString(), object); @@ -94,7 +98,7 @@ public class JSONSchemaGenerator { } } else if (propertyObjType.equals(BasicConstant.STRING)) { // 先设置空值 - concept.put(propertyName, ""); + concept.put(propertyName,""); if (object.has("format")) { String propertyFormat = object.get("format").getAsString(); if (propertyFormat.equals("date-time")) {