Skip to content

Commit

Permalink
[*]修复swagger文档必填字段显示问题,responseBody属性字段过滤level字段
Browse files Browse the repository at this point in the history
  • Loading branch information
Gd-Lianjy committed Aug 8, 2021
1 parent a1f1efe commit a5e92dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private Map<String, Object> parseResponse(ApiInfo info) {
}

private Map<String, Object> doProcessDefinition(BaseDefinition target, ApiInfo info, String parentName, String definitionType, int level) {
Map<String, Object> result = new HashMap<>(3);
Map<String, Object> result = new HashMap<>(4);
result.put("description", target.getDescription());
if (DataType.Array == target.getDataType()) {
if (!CollectionUtils.isEmpty(target.getChildren())) {
Expand All @@ -201,15 +201,19 @@ private Map<String, Object> doProcessDefinition(BaseDefinition target, ApiInfo i
String groupName = groupServiceProvider.getFullName(info.getGroupId()).replace("/", "-");
String voName = groupName + "«" + info.getPath().replaceFirst("/", "").replaceAll("/", "_") + (StringUtils.equals("response", definitionType) ? "«response«" : "«request«") + parentName + target.getName() + "»»»";

Map<String, Object> definition = new HashMap<>(3);
Map<String, Object> definition = new HashMap<>(4);
Map<String, Map<String, Object>> properties = new HashMap<>(target.getChildren().size());
Set<String> requiredSet = new HashSet <>(target.getChildren().size());
for (BaseDefinition obj : target.getChildren()) {
properties.put(obj.getName(), doProcessDefinition(obj, info, parentName + target.getName() + "_", definitionType, level + 1));
if (obj.isRequired()) {
requiredSet.add(obj.getName());
}
}
definition.put("properties", properties);
definition.put("description", target.getDescription());
definition.put("type", target.getDataType().getJavascriptType());

definition.put("required", requiredSet);
if (this.DEFINITION_MAP.containsKey(voName)) {
// TODO 应该不会出现名字都一样的
voName = voName.replace("»»»", "_" + level + "»»»");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
watch: {
responseBody: {
handler(responseBodyArr) {
this.info.responseBodyDefinition = responseBodyArr[0]
this.info.responseBodyDefinition = deepClone(responseBodyArr[0], ['level'])
},
deep: true
}
Expand Down
35 changes: 21 additions & 14 deletions magic-editor/src/console/src/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,28 @@ const isArray = (arr) => {
return Object.prototype.toString.call(arr) === '[object Array]';
}

// 深度克隆
const deepClone = (obj) => {
// 对常见的“非”值,直接返回原来值
if([null, undefined, NaN, false].includes(obj)) return obj;
if(typeof obj !== "object" && typeof obj !== 'function') {
//原始类型直接返回
return obj;
}
var o = isArray(obj) ? [] : {};
for(let i in obj) {
if(obj.hasOwnProperty(i)){
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
/*
* @Description 深度克隆
* ignoreFields 忽略克隆对象字段,只针对对象有效
*/
const deepClone = (obj, ignoreFields = []) => {
// 对常见的“非”值,直接返回原来值
if([null, undefined, NaN, false].includes(obj)) return obj;
if(typeof obj !== "object" && typeof obj !== 'function') {
//原始类型直接返回
return obj;
}
}
return o;
var o = isArray(obj) ? [] : {};
for(let i in obj) {
if(obj.hasOwnProperty(i)){
o[i] = typeof obj[i] === "object" ? deepClone(obj[i], ignoreFields) : obj[i];
}
}
// 清除忽略字段
ignoreFields.forEach(i => {
delete o[i]
})
return o;
}

// 展示锚点对象
Expand Down

0 comments on commit a5e92dc

Please sign in to comment.