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