fix(接口测试): 修复swagger导出json格式问题

--bug=1026582 --user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001026582
This commit is contained in:
guoyuqi 2023-06-28 11:30:40 +08:00 committed by 刘瑞斌
parent 9b81ddf56b
commit 937532c093
1 changed files with 11 additions and 5 deletions

View File

@ -526,14 +526,18 @@ public class Swagger3Parser extends SwaggerAbstractParser {
Schema items = ((ArraySchema) schema).getItems(); Schema items = ((ArraySchema) schema).getItems();
item.setType(PropertyConstant.ARRAY); item.setType(PropertyConstant.ARRAY);
JsonSchemaItem arrayItem = parseSchema(items, refSet); JsonSchemaItem arrayItem = parseSchema(items, refSet);
Map<String, String> mock = new LinkedHashMap<>(); Map<String, Object> mock = new LinkedHashMap<>();
if (arrayItem != null && MapUtils.isNotEmpty(arrayItem.getProperties())) { if (arrayItem != null && MapUtils.isNotEmpty(arrayItem.getProperties())) {
arrayItem.getProperties().forEach((k, v) -> { arrayItem.getProperties().forEach((k, v) -> {
mock.put(k, StringUtils.isBlank(v.getMock().get(PropertyConstant.MOCK).toString()) ? v.getType() : mock.put(k, StringUtils.isBlank(v.getMock().get(PropertyConstant.MOCK).toString()) ? v.getType() :
v.getMock().get(PropertyConstant.MOCK).toString()); v.getMock().get(PropertyConstant.MOCK).toString());
}); });
} }
if (item.getMock() != null) {
item.getMock().put(PropertyConstant.MOCK, JSONUtil.toJSONString(mock)); item.getMock().put(PropertyConstant.MOCK, JSONUtil.toJSONString(mock));
} else {
item.setMock(mock);
}
if (arrayItem != null) { if (arrayItem != null) {
item.getItems().add(arrayItem); item.getItems().add(arrayItem);
} }
@ -908,9 +912,11 @@ public class Swagger3Parser extends SwaggerAbstractParser {
public Object getJsonSchemaValue(JSONObject item) { public Object getJsonSchemaValue(JSONObject item) {
JSONObject mock = item.optJSONObject(PropertyConstant.MOCK); JSONObject mock = item.optJSONObject(PropertyConstant.MOCK);
if (mock != null) { if (mock != null) {
if (StringUtils.isNotBlank(mock.optString("mock"))) {
Object value = mock.get(PropertyConstant.MOCK); Object value = mock.get(PropertyConstant.MOCK);
return value; return value;
} }
}
return null; return null;
} }
@ -1046,7 +1052,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
String value = obj.optString("value"); String value = obj.optString("value");
if (StringUtils.isBlank(value)) { if (StringUtils.isBlank(value)) {
JSONObject mock = obj.optJSONObject(PropertyConstant.MOCK); JSONObject mock = obj.optJSONObject(PropertyConstant.MOCK);
if (mock != null) { if (mock != null && StringUtils.isNotBlank(mock.optString("mock"))) {
Object mockValue = mock.get(PropertyConstant.MOCK); Object mockValue = mock.get(PropertyConstant.MOCK);
property.put("example", mockValue); property.put("example", mockValue);
} else { } else {