Skip to content

Commit 3bb1c5a

Browse files
committed
APIAuto:CodeUtil 新增 extractTableNames
1 parent f636a3c commit 3bb1c5a

1 file changed

Lines changed: 53 additions & 5 deletions

File tree

  • APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/apijson

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if (typeof window == 'undefined') {
2828
* @author Lemon
2929
*/
3030
var CodeUtil = {
31+
DEBUG: true,
3132
TAG: 'CodeUtil',
3233
APP_NAME: 'APIAuto',
3334
DIVIDER: '/',
@@ -82,6 +83,38 @@ var CodeUtil = {
8283
thirdParty: 'YAPI',
8384
thirdPartyApiMap: null, // {}
8485

86+
extractTableNames: function(keys) {
87+
if (StringUtil.isEmpty(keys)) {
88+
return null;
89+
}
90+
91+
var ks = [];
92+
for (var i = 0; i < keys.length; i ++) {
93+
var k = StringUtil.trim(keys[i]);
94+
while (k.startsWith('_')) {
95+
k = k.substring(1);
96+
}
97+
while (k.endsWith('_')) {
98+
k = k.substring(0, k.length - 1);
99+
}
100+
101+
if (StringUtil.isListKey(k)) {
102+
k = k.substring(0, k.length - 4);
103+
}
104+
else if (StringUtil.isArrKey(k)) {
105+
k = k.substring(0, k.length - (k.toLowerCase().endsWith('array') ? 5 : 4));
106+
}
107+
else if (StringUtil.isSetKey(k)) {
108+
k = k.substring(0, k.length - 3);
109+
}
110+
111+
if (StringUtil.isTableName(k)) {
112+
ks.push(k);
113+
}
114+
}
115+
116+
return ks;
117+
}
85118

86119
/**生成JSON的注释
87120
* @param reqStr //已格式化的JSON String
@@ -91,13 +124,24 @@ var CodeUtil = {
91124
* @param language
92125
* @return parseComment
93126
*/
94-
parseComment: function (reqStr, tableList, method, database, language, isReq, standardObj, isExtract, isWarning, isAPIJSONRouter) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
127+
parseComment: function (reqStr, tableList, method, schema, database, language, isReq, standardObj, isExtract, isWarning, isAPIJSONRouter, search) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
95128
if (StringUtil.isEmpty(reqStr)) {
96129
return '';
97130
}
98131

99132
var reqObj = JSON5.parse(reqStr);
100133

134+
var possibleTables = CodeUtil.extractTableNames(StringUtil.split(method, '/', true)) || [];
135+
var searchTables = CodeUtil.extractTableNames(StringUtil.split(search, '/', true)) || [];
136+
for (var i = 0; i < possibleTables.length; i ++) {
137+
var t = possibleTables[i];
138+
if (StringUtil.isEmpty(t) || searchTables.indexOf(t) >= 0) {
139+
continue;
140+
}
141+
searchTables.push(t);
142+
}
143+
possibleTables = searchTables;
144+
101145
var methodInfo = JSONObject.parseUri(method, isReq) || {};
102146
method = methodInfo.method;
103147
var isRestful = methodInfo.isRestful;
@@ -111,7 +155,7 @@ var CodeUtil = {
111155
var lines = reqStr.split('\n');
112156

113157
var depth = startName == null ? 0 : 1;
114-
var names = startName == null ? [] : [startName];
158+
var names = startName == null ? [] : [startName];
115159
var isInSubquery = false;
116160

117161
var curObj = {
@@ -6340,10 +6384,13 @@ res_data = rep.json()
63406384
name = ks[ks.length - 2];
63416385
key = ks[ks.length - 1];
63426386
names = ks.slice(0, ks.length - 1)
6343-
63446387
var nk = name.endsWith('[]') ? name.substring(0, name.length - 2) : name;
6345-
if (JSONObject.isTableKey(nk) != true) {
6346-
nk = name;
6388+
var tbl = nk;
6389+
if (JSONObject.isTableKey(nk)) {
6390+
nk = key;
6391+
} else {
6392+
nk = tbl;
6393+
tbl = ks[ks.length - 3];
63476394
}
63486395

63496396
extraComment = CodeUtil.getComment4Request(tableList, null, nk, { [key]:value }, method, isInSubquery, database, language, isReq, ks.slice(0, ks.length - 2), isRestful, standardObj, isWarning, false).trim();
@@ -6497,6 +6544,7 @@ res_data = rep.json()
64976544
if ((isReq != true || method == 'POST' || method == 'PUT') && JSONObject.isArrayKey(name)) {
64986545
var aliaIndex = name.indexOf(':');
64996546
var objName = name.substring(0, aliaIndex >= 0 ? aliaIndex : name.length - 2);
6547+
schema = value['@schema'] || schema;
65006548

65016549
if (JSONObject.isTableKey(objName)) {
65026550
var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database, language, isReq != true || isRestful, isReq, pathKeys, isRestful, value, null, null, null, isWarning);

0 commit comments

Comments
 (0)