diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java index a5c15a1393..a73ee76db2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java @@ -458,13 +458,18 @@ public class Swagger3Parser extends SwaggerAbstractParser { private JsonSchemaItem parseSchema(Schema schema, Set refSet) { if (schema == null) return null; JsonSchemaItem item = new JsonSchemaItem(); + if(schema.getRequired()!=null){ + item.setRequired(schema.getRequired()); + } if (StringUtils.isNotBlank(schema.get$ref())) { if (refSet.contains(schema.get$ref())) return item; item.setType("object"); refSet.add(schema.get$ref()); Schema modelByRef = getModelByRef(schema.get$ref()); - if (modelByRef != null) + if (modelByRef != null){ item.setProperties(parseSchemaProperties(modelByRef, refSet)); + item.setRequired(modelByRef.getRequired()); + } } else if (schema instanceof ArraySchema) { Schema items = ((ArraySchema) schema).getItems(); item.setType("array"); @@ -715,6 +720,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { String type = requestBody.getString("type"); JSONObject parsedParam = new JSONObject(); + if(required!=null){ + parsedParam.put("required",required); + } if (StringUtils.isNotBlank(type)) { if (StringUtils.equals(type, "array")) { JSONObject items = requestBody.getJSONObject("items"); @@ -727,18 +735,11 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else if (StringUtils.equals(type, "object")) { parsedParam.put("type", "object"); JSONObject properties = requestBody.getJSONObject("properties"); - JSONObject swaggerProperties = new JSONObject(); - properties.keySet().forEach((k) -> { - JSONObject item = buildJsonSchema(properties.getJSONObject(k), required); - if (required != null && required.contains(k)) { - item.put("required", true); - } - swaggerProperties.put(k, item); - }); + if (StringUtils.isNotBlank(requestBody.getString("description"))) { parsedParam.put("description", requestBody.getString("description")); } - parsedParam.put("properties", swaggerProperties); + parsedParam.put("properties", properties); } else if (StringUtils.equals(type, "integer")) { parsedParam.put("type", "integer"); parsedParam.put("format", "int64");