Skip to content

Commit

Permalink
fix(接口测试):修复接口导出swagger3.0部分响应体丢失问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomeinvG authored and fit2-zhao committed Mar 27, 2023
1 parent bf31999 commit 41c64a9
Showing 1 changed file with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,33 @@ private JSONObject buildJsonSchema(JSONObject requestBody, JSONArray required) {
}
if (StringUtils.isNotBlank(type)) {
if (StringUtils.equals(type, "array")) {
JSONObject items = requestBody.getJSONObject("items");
JSONObject itemProperties = new JSONObject();
parsedParam.put("type", "array");
JSONObject item = buildJsonSchema(items, required);
JSONArray items = requestBody.getJSONArray("items");
if (items != null) {
JSONObject itemsObject = new JSONObject();
if (items.size() > 0) {
items.forEach(item -> {
if (item instanceof JSONObject) {
JSONObject itemJson = buildJsonSchema((JSONObject) item, required);
if (itemJson != null) {
Set<String> keys = itemJson.keySet();
for (String key : keys) {
itemProperties.put(key, itemJson.get(key));
}
}
}
});
}
itemsObject.put("properties", itemProperties);
parsedParam.put("items", itemsObject.getJSONObject("properties"));
} else {
parsedParam.put("items", new JSONObject());
}

if (StringUtils.isNotBlank(requestBody.getString("description"))) {
parsedParam.put("description", requestBody.getString("description"));
}
parsedParam.put("items", item);
} else if (StringUtils.equals(type, "object")) {
parsedParam.put("type", "object");
JSONObject properties = requestBody.getJSONObject("properties");
Expand Down Expand Up @@ -1058,8 +1078,19 @@ private JSONObject buildFormDataSchema(JSONObject kvs) {
property.put("description", obj.getString("description"));
property.put("required", obj.getString("required"));
if (obj.getJSONObject("properties") != null) {
JSONObject properties1 = buildFormDataSchema(obj.getJSONObject("properties"));
property.put("properties", properties1.getJSONObject("properties"));
JSONObject childProperties = buildFormDataSchema(obj.getJSONObject("properties"));
property.put("properties", childProperties.getJSONObject("properties"));
} else {
JSONObject childProperties = buildJsonSchema(obj, new JSONArray());
if (StringUtils.equalsIgnoreCase(obj.getString("type"), "array")) {
if (childProperties.getJSONObject("items") != null) {
property.put("items", childProperties.getJSONObject("items"));
}
} else {
if (childProperties.getJSONObject("properties") != null) {
property.put("properties", childProperties.getJSONObject("properties"));
}
}
}
properties.put(key, property);
}
Expand Down Expand Up @@ -1200,9 +1231,16 @@ private JSONObject buildContent(JSONObject respOrReq, List<JSONObject> schemas)
required = jsonObject.getJSONArray("required");
}
if (required == null) {
JSONObject items = jsonObject.getJSONObject("items");
if (items != null) {
required = items.getJSONArray("required");
JSONArray items = jsonObject.getJSONArray("items");
if (items != null && items.size() > 0) {
JSONArray finalRequired = new JSONArray();
items.forEach(item -> {
if (item instanceof JSONObject) {
JSONObject itemRequired = ((JSONObject) item).getJSONObject("required");
finalRequired.add(itemRequired);
}
});
required = finalRequired;
}
}
bodyInfo = buildJsonSchema(jsonObject, required);
Expand Down

0 comments on commit 41c64a9

Please sign in to comment.