Skip to content

Commit 7db7986

Browse files
committed
APIAuto:解决有时获取不到合适的表和字段文档
1 parent 6b4b5c0 commit 7db7986

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/apijson/CodeUtil.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6787,7 +6787,8 @@ res_data = rep.json()
67876787
if (standardObj != null) {
67886788
var parentObj = pathKeys == null || pathKeys.length <= 0 ? null : JSONResponse.getStandardByPath(standardObj, pathKeys.slice(0, pathKeys.length - 1));
67896789
var targetValues = parentObj == null ? null : parentObj.values;
6790-
var targetObj = targetValues == null ? null : (targetValues[0] || {})[pathKeys[pathKeys.length - 1]]; // JSONResponse.getStandardByPath(standardObj, pathKeys);
6790+
var lastKey = pathKeys == null ? null : pathKeys[pathKeys.length - 1]
6791+
var targetObj = targetValues == null ? null : (targetValues[0] || {})[lastKey] || {}; // JSONResponse.getStandardByPath(standardObj, pathKeys);
67916792

67926793
var t = targetObj == null ? null : targetObj.type;
67936794
var targetComment = targetObj == null ? null : targetObj.comment;
@@ -6812,15 +6813,22 @@ res_data = rep.json()
68126813
var name = targetObj == null || StringUtil.isEmpty(targetObj.name, true) ? null : targetObj.name;
68136814
if (StringUtil.isNotEmpty(parentName, true) || StringUtil.isNotEmpty(name, true)) {
68146815
var pn = parentName || tableName;
6815-
var n = name || columnName;
6816+
var n = name || columnName || lastKey;
68166817
var isValObj = isValueNotObject != true; // && StringUtil.isName(pn)
68176818

68186819
c = CodeUtil.getCommentFromDoc(tableList, isValObj ? n : pn, isValObj ? null : n
6819-
, method, database, language, onlyTableAndColumn, isReq, pathKeys, value, ignoreError, null, isSubquery, isWarning);
6820+
, method, database, language, onlyTableAndColumn, isReq, pathKeys, isRestful, value, ignoreError, null, isSubquery, isWarning);
68206821
if (StringUtil.isNotEmpty(c, true)) {
68216822
return (isValObj && StringUtil.isNotEmpty(name, true) ? StringUtil.trim(name) : CodeUtil.getType4Language(language, t, true))
68226823
+ (targetObj.notEmpty ? '! ' : (targetObj.notNull ? ', ' : '? ')) + StringUtil.trim(c);
68236824
}
6825+
6826+
if (StringUtil.isEmpty(tableName, true)) {
6827+
tableName = isValObj ? n : pn;
6828+
}
6829+
if (StringUtil.isEmpty(columnName, true)) {
6830+
columnName = isValObj ? null : n;
6831+
}
68246832
}
68256833
}
68266834

@@ -6947,7 +6955,8 @@ res_data = rep.json()
69476955
return c;
69486956
}
69496957
else {
6950-
if (c != null) { // 可能存在但只是没注释 StringUtil.isEmpty(c, true) == false) {
6958+
// if (c != null) { // 可能存在但只是没注释
6959+
if (StringUtil.isEmpty(c, true) == false) {
69516960
return isWarning ? ' ' : c;
69526961
}
69536962
}
@@ -7016,7 +7025,7 @@ res_data = rep.json()
70167025
//Table
70177026
table = item == null ? null : (isTSQL ? item.AllTable : (database != 'SQLSERVER' ? item.Table : item.SysTable));
70187027
var table_name = table == null ? null : table.table_name;
7019-
if (table_name == null || table_name.replaceAll('_', '').toLowerCase().endsWith(tableName.replaceAll('_', '').toLowerCase()) != true) { // tableName != CodeUtil.getModelName(table.table_name)) {
7028+
if (table_name == null || table_name.replaceAll('_', '').toLowerCase() != tableName.replaceAll('_', '').toLowerCase()) { // tableName != CodeUtil.getModelName(table.table_name)) {
70207029
continue;
70217030
}
70227031
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
@@ -7253,7 +7262,7 @@ res_data = rep.json()
72537262
for (var j = 0; j < columnList.length; j++) {
72547263
column = (columnList[j] || {})[isTSQL ? 'AllColumn' : 'Column'];
72557264
name = column == null ? null : column.column_name;
7256-
if (name == null || key != name) {
7265+
if (name == null || key.replaceAll('_', '').toLowerCase() != name.replaceAll('_', '').toLowerCase()) {
72577266
if (name != null) {
72587267
columnNames.push(name)
72597268
}

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/apijson/JSONResponse.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,15 @@ var JSONResponse = {
18111811
}
18121812
} catch (e) {
18131813
}
1814+
} else if (tgt instanceof Object && tgt.type == 'array') {
1815+
try {
1816+
var n = Number.parseInt(k);
1817+
if (Number.isSafeInteger(n)) {
1818+
tgt = tgt.values[0];
1819+
continue;
1820+
}
1821+
} catch (e) {
1822+
}
18141823
}
18151824
}
18161825

@@ -1883,6 +1892,11 @@ var JSONResponse = {
18831892
tgt.values[0] = child;
18841893
}
18851894

1895+
if (k == 0) {
1896+
tgt = child;
1897+
continue;
1898+
}
1899+
18861900
if (child[k] == null) {
18871901
child[k] = {};
18881902
}
@@ -1911,6 +1925,14 @@ var JSONResponse = {
19111925
var name = nullable || notEmpty ? prefix.substring(0, prefix.length - 1) : prefix
19121926
if (StringUtil.isName(name)) {
19131927
tgt.name = name
1928+
if (tgt.type == 'array') {
1929+
var values = tgt.values || []
1930+
var child = values[0]
1931+
if (child != null && StringUtil.isEmpty(child.name, true)) {
1932+
child.name = name
1933+
child.comment = comment
1934+
}
1935+
}
19141936
} else {
19151937
nullable = notEmpty = null
19161938
}

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/js/main.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3105,7 +3105,7 @@ https://github.com/Tencent/APIJSON/issues
31053105
}
31063106
}
31073107

3108-
if ((isExportRandom != true || btnIndex == 1) && StringUtil.isEmpty(this.exTxt.name, true)) {
3108+
if ((isExportRandom != true || btnIndex == 1) && StringUtil.isEmpty(this.exTxt.name, true) && ! this.isEditResponse) {
31093109
alert('请输入接口名!')
31103110
return
31113111
}
@@ -8543,6 +8543,8 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
85438543
// 'table_name!$': ['\\_%', 'sys\\_%', 'system\\_%'],
85448544
'table_name$': search,
85458545
'table_comment$': this.database == 'POSTGRESQL' ? null : search,
8546+
'table_schema!$': '\\_%',
8547+
'table_name!$': '\\_%',
85468548
'@combine': search == null || this.database == 'POSTGRESQL' ? null : 'table_name$,table_comment$',
85478549
'table_name{}@': 'sql',
85488550
'@order': 'table_name+', //MySQL 8 SELECT `table_name` 返回的仍然是大写的 TABLE_NAME,需要 AS 一下

0 commit comments

Comments
 (0)