Skip to content

Commit d8ce819

Browse files
committed
新增历史请求记录;新增管理员账号;新增配置schema和托管服务器;优化自动化接口回归测试;优化自动注释;新增文档视频源码等入口;修复bug
1 parent 28b017e commit d8ce819

File tree

8 files changed

+1028
-338
lines changed

8 files changed

+1028
-338
lines changed

apijson/CodeUtil.js

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ var CodeUtil = {
6262
else {
6363
if (line.endsWith('}')) {
6464
if (line.endsWith('{}')) { //对象,判断是不是Table,再加对应的注释
65-
names[depth] = key;
6665
comment = CodeUtil.getComment4Request(tableList, null, key, null, method);
6766
}
6867
else {
@@ -225,20 +224,22 @@ var CodeUtil = {
225224
const isTable = isSmart && JSONObject.isTableKey(JSONResponse.getTableName(key));
226225

227226
const column = isTable ? value['@column'] : null;
228-
const order = isTable ? value['@order'] : null;
229227
const group = isTable ? value['@group'] : null;
230228
const having = isTable ? value['@having'] : null;
229+
const order = isTable ? value['@order'] : null;
231230
const combine = isTable ? value['@combine'] : null;
232231
const schema = isTable ? value['@schema'] : null;
232+
const database = isTable ? value['@database'] : null;
233233
const role = isTable ? value['@role'] : null;
234234

235235
if (isTable) {
236236
delete value['@column'];
237-
delete value['@order'];
238237
delete value['@group'];
239238
delete value['@having'];
239+
delete value['@order'];
240240
delete value['@combine'];
241241
delete value['@schema'];
242+
delete value['@database'];
242243
delete value['@role'];
243244
}
244245

@@ -247,11 +248,12 @@ var CodeUtil = {
247248
const name = CodeUtil.getTableKey(JSONResponse.getSimpleName(key));
248249
if (isTable) {
249250
s = column == null ? s : s + '\n' + name + '.setColumn(' + CodeUtil.getJavaValue(name, key, column) + ');';
250-
s = order == null ? s : s + '\n' + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
251251
s = group == null ? s : s + '\n' + name + '.setGroup(' + CodeUtil.getJavaValue(name, key, group) + ');';
252252
s = having == null ? s : s + '\n' + name + '.setHaving(' + CodeUtil.getJavaValue(name, key, having) + ');';
253+
s = order == null ? s : s + '\n' + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
253254
s = combine == null ? s : s + '\n' + name + '.setCombine(' + CodeUtil.getJavaValue(name, key, combine) + ');';
254255
s = schema == null ? s : s + '\n' + name + '.setSchema(' + CodeUtil.getJavaValue(name, key, schema) + ');';
256+
s = database == null ? s : s + '\n' + name + '.setDatabase(' + CodeUtil.getJavaValue(name, key, database) + ');';
255257
s = role == null ? s : s + '\n' + name + '.setRole(' + CodeUtil.getJavaValue(name, key, role) + ');';
256258
}
257259

@@ -270,6 +272,18 @@ var CodeUtil = {
270272
if (key == 'version') {
271273
return '\n' + parentKey + '.setVersion(' + CodeUtil.getJavaValue(name, key, value) + ');';
272274
}
275+
if (key == 'format') {
276+
return '\n' + parentKey + '.setFormat(' + CodeUtil.getJavaValue(name, key, value) + ');';
277+
}
278+
if (key == '@schema') {
279+
return '\n' + parentKey + '.setSchema(' + CodeUtil.getJavaValue(name, key, value) + ');';
280+
}
281+
if (key == '@database') {
282+
return '\n' + parentKey + '.setDatabase(' + CodeUtil.getJavaValue(name, key, value) + ');';
283+
}
284+
if (key == '@role') {
285+
return '\n' + parentKey + '.setRole(' + CodeUtil.getJavaValue(name, key, value) + ');';
286+
}
273287
}
274288
return '\n' + parentKey + '.put("' + key + '", ' + CodeUtil.getJavaValue(name, key, value) + ');';
275289
}
@@ -827,6 +841,7 @@ var CodeUtil = {
827841
OWNER: '拥有者',
828842
ADMIN: '管理员'
829843
},
844+
REQUEST_DATABASE_KEYS: ['MYSQL', 'POSTGRESQL', 'ORACLE'],
830845

831846
/**获取请求JSON的注释
832847
* @param tableList
@@ -875,17 +890,17 @@ var CodeUtil = {
875890
if (JSONObject.isArrayKey(name)) {
876891
switch (key) {
877892
case 'count':
878-
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('最多数量', false, ' ');
893+
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('最多数量: 例如 5 10 20 ...', false, ' ');
879894
case 'page':
880895
if (CodeUtil.getType4Request(value) != 'number') {
881896
return ' ! value必须是Number类型!';
882897
}
883-
return value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码', false, ' ');
898+
return value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码: 例如 0 1 2 ...', false, ' ');
884899
case 'query':
885900
var query = CodeUtil.QUERY_TYPES[value];
886901
return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-数据 1-总数 2-全部', false, ' ');
887902
case 'join':
888-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('多表连接:LEFT JOIN < ,RIGHT JOIN > ,INNER JOIN & | ! ', false, ' ');
903+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('多表连接:例如 &/User/id@,</Comment/momentId@,...', false, ' ');
889904
}
890905
return '';
891906
}
@@ -894,29 +909,32 @@ var CodeUtil = {
894909
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
895910

896911
if (JSONObject.isTableKey(objName)) {
912+
switch (key) {
913+
case '@column':
914+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段:例如 id,name;json_length(contactIdList):contactCount;...', false, ' ');
915+
case '@group':
916+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式:例如 userId,momentId,...', false, ' ');
917+
case '@having':
918+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('SQL函数:例如 max(id)>100;sum(balance)<=10000;...', false, ' ');
919+
case '@order':
920+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序,例如 name+,date-,...', false, ' ');
921+
case '@combine':
922+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合:例如 name?,|tag?,&id{},!id,...', false, ' ');
923+
case '@schema':
924+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间:例如 sys apijson ...', false, ' ');
925+
case '@database':
926+
try {
927+
value = value.substring(1, value.length - 1).toUpperCase();
928+
} catch (e) {}
929+
return CodeUtil.REQUEST_DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.REQUEST_DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库:例如 MYSQL POSTGRESQL ORACLE ...', false, ' ');
930+
case '@role':
931+
try {
932+
value = value.substring(1, value.length - 1).toUpperCase();
933+
} catch (e) {}
934+
var role = CodeUtil.REQUEST_ROLE[value];
935+
return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.REQUEST_ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
936+
}
897937
if (key.startsWith('@')) {
898-
switch (key) {
899-
case '@column':
900-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段:例如 id,name,json_length(contactIdList):contactCount...', false, ' ');
901-
case '@order':
902-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序,例如 name+,date-,...', false, ' ');
903-
case '@group':
904-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式:例如 userId', false, ' ');
905-
case '@having':
906-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('SQL函数:例如 max(id)>100,sum(balance)<=10000,...', false, ' ');
907-
case '@combine':
908-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合:例如 name?,|tag?,&id{},!id,...', false, ' ');
909-
case '@schema':
910-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('数据库:例如 sys', false, ' ');
911-
case '@correct':
912-
return value != null ? ' ! value必须是Object类型!' : CodeUtil.getComment('字段校正', false, ' ');
913-
case '@role':
914-
try {
915-
value = value.substring(1, value.length - 1).toUpperCase();
916-
} catch (e) {}
917-
var role = CodeUtil.REQUEST_ROLE[value];
918-
return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.REQUEST_ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
919-
}
920938
return '';
921939
}
922940
var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method);
@@ -930,12 +948,21 @@ var CodeUtil = {
930948
if (method == 'GET' || method == 'HEAD') {
931949
return '';
932950
}
933-
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('请求密钥', false, ' ');
951+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('请求密钥:例如 User Comment[] Privacy-CIRCLE ...', false, ' ');
934952
case 'version':
935953
if (method == 'GET' || method == 'HEAD') {
936954
return '';
937955
}
938-
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('版本号', false, ' ');
956+
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('版本号: 例如 1 2 3 ...', false, ' ');
957+
case 'format':
958+
return CodeUtil.getType4Request(value) != 'boolean' ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否', false, ' ');
959+
case '@schema':
960+
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间:例如 sys apijson ...', false, ' ');
961+
case '@database':
962+
try {
963+
value = value.substring(1, value.length - 1).toUpperCase();
964+
} catch (e) {}
965+
return CodeUtil.REQUEST_DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.REQUEST_DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库:例如 MYSQL POSTGRESQL ORACLE ...', false, ' ');
939966
case '@role':
940967
try {
941968
value = value.substring(1, value.length - 1).toUpperCase();

apijson/JSONRequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function format(json) {
189189
}
190190

191191
function log(tag, msg) {
192-
console.log(tag + '.' + msg);
192+
//console.log(tag + '.' + msg);
193193
}
194194

195195
/**将json字符串转为JSON对象

apijson/JSONResponse.js

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ var JSONResponse = {
194194
COMPARE_NO_STANDARD: -1,
195195
COMPARE_EQUAL: 0,
196196
COMPARE_KEY_MORE: 1,
197+
COMPARE_LENGTH_CHANGE: 2,
197198
COMPARE_VALUE_CHANGE: 2,
198199
COMPARE_KEY_LESS: 3,
199200
COMPARE_TYPE_CHANGE: 4,
@@ -207,22 +208,38 @@ var JSONResponse = {
207208
3-对象缺少字段/整数变小数,黄色;
208209
4-code/值类型 改变,红色;
209210
*/
210-
compareResponse: function(target, real) {
211+
compareResponse: function(target, real, folder, isMachineLearning) {
211212
if (target == null || target.code == null) {
212-
return JSONResponse.COMPARE_NO_STANDARD; //未上传对比标准(正确的结果)
213+
return {
214+
code: JSONResponse.COMPARE_NO_STANDARD, //未上传对比标准
215+
msg: '没有校验标准!',
216+
path: folder == null ? '' : folder
217+
};
213218
}
214219
if (target.code != real.code) {
215-
return JSONResponse.COMPARE_CODE_CHANGE;
220+
return {
221+
code: JSONResponse.COMPARE_CODE_CHANGE,
222+
msg: '状态码改变!',
223+
path: folder == null ? '' : folder
224+
};
216225
}
217226

227+
var tCode = target.code;
228+
var rCode = real.code;
229+
218230
delete target.code;
219231
delete real.code;
220232

221233
//可能提示语变化,也要提示
222234
// delete target.msg;
223235
// delete real.msg;
224236

225-
return JSONResponse.compare(target, real);
237+
var result = JSONResponse.compareWithBefore(target, real, folder);
238+
239+
target.code = tCode;
240+
real.code = rCode;
241+
242+
return result;
226243
},
227244

228245
/**测试compare: 对比 新的请求与上次请求的结果
@@ -232,76 +249,116 @@ var JSONResponse = {
232249
3-缺少字段/整数变小数,黄色;
233250
4-类型/code 改变,红色;
234251
*/
235-
compare: function(target, real) {
252+
compareWithBefore: function(target, real, folder) {
253+
folder = folder == null ? '' : folder;
254+
236255
if (target == null) {
237-
return real == null ? JSONResponse.COMPARE_EQUAL : JSONResponse.COMPARE_KEY_MORE;
256+
return {
257+
code: real == null ? JSONResponse.COMPARE_EQUAL : JSONResponse.COMPARE_KEY_MORE,
258+
msg: real == null ? '结果正确' : '是新增的',
259+
path: real == null ? '' : folder,
260+
value: real
261+
};
238262
}
239263
if (real == null) { //少了key
240-
return JSONResponse.COMPARE_KEY_LESS;
264+
return {
265+
code: JSONResponse.COMPARE_KEY_LESS,
266+
msg: '是缺少的',
267+
path: folder,
268+
value: real
269+
};
241270
}
242271

243272
var type = typeof target;
244273
if (type != typeof real) { //类型改变
245-
return JSONResponse.COMPARE_TYPE_CHANGE;
274+
return {
275+
code: JSONResponse.COMPARE_TYPE_CHANGE,
276+
msg: '值改变',
277+
path: folder,
278+
value: real
279+
};
246280
}
247281

248-
var max = JSONResponse.COMPARE_EQUAL;
249-
var each = JSONResponse.COMPARE_EQUAL;
282+
// var max = JSONResponse.COMPARE_EQUAL;
283+
// var each = JSONResponse.COMPARE_EQUAL;
284+
285+
var max = {
286+
code: JSONResponse.COMPARE_EQUAL,
287+
msg: '结果正确',
288+
path: '', //导致正确时也显示 folder,
289+
value: null //导致正确时也显示 real
290+
};
291+
292+
var each;
293+
250294
if (target instanceof Array) { // JSONArray
251295
var all = target[0];
252296
for (var i = 1; i < length; i++) { //合并所有子项, Java类型是稳定的,不会出现两个子项间同名字段对应值类型不一样
253297
all = JSONResponse.deepMerge(all, target[i]);
254298
}
255299
//下载需要看源JSON real = [all];
256300

257-
each = JSONResponse.compare(target[0], all);
301+
each = JSONResponse.compareWithBefore(target[0], all, JSONResponse.getAbstractPath(folder, i));
258302

259-
if (max < each) {
303+
if (max.code < each.code) {
260304
max = each;
261305
}
262306

263-
if (max < JSONResponse.COMPARE_VALUE_CHANGE) {
307+
if (max.code < JSONResponse.COMPARE_VALUE_CHANGE) {
264308
if (target.length != real.length || (JSON.stringify(target) != JSON.stringify(real))) {
265-
max = JSONResponse.COMPARE_VALUE_CHANGE;
309+
max.code = JSONResponse.COMPARE_VALUE_CHANGE;
310+
max.msg = '值改变';
311+
max.path = folder;
312+
max.value = real;
266313
}
267314
}
268315
}
269316
else if (target instanceof Object) { // JSONObject
270317
var tks = Object.keys(target);
271318
var key;
272-
for (var i = 0; i< tks.length; i++) { //遍历并递归下一层
319+
for (var i = 0; i < tks.length; i++) { //遍历并递归下一层
273320
key = tks[i];
274321
if (key == null) {
275322
continue;
276323
}
277324

278-
each = JSONResponse.compare(target[key], real[key]);
279-
if (max < each) {
325+
each = JSONResponse.compareWithBefore(target[key], real[key], JSONResponse.getAbstractPath(folder, key));
326+
if (max.code < each.code) {
280327
max = each;
281328
}
282-
if (max >= JSONResponse.COMPARE_TYPE_CHANGE) {
329+
if (max.code >= JSONResponse.COMPARE_TYPE_CHANGE) {
283330
break;
284331
}
285332
}
286333

287334

288-
if (max < JSONResponse.COMPARE_KEY_MORE) { //多出key
335+
if (max.code < JSONResponse.COMPARE_KEY_MORE) { //多出key
289336
for (var k in real) {
290337
if (k != null && tks.indexOf(k) < 0) {
291-
max = JSONResponse.COMPARE_KEY_MORE;
338+
max.code = JSONResponse.COMPARE_KEY_MORE;
339+
max.msg = '是新增的';
340+
max.path = JSONResponse.getAbstractPath(folder, k);
341+
max.value = real[k];
342+
break;
292343
}
293344
}
294345
}
295346
}
296347
else { // Boolean, Number, String
297348
if (type == 'number') { //数字类型由整数变为小数
298349
if (String(target).indexOf('.') < 0 && String(real).indexOf('.') >= 0) {
299-
return JSONResponse.COMPARE_NUMBER_TYPE_CHANGE;
350+
max.code = JSONResponse.COMPARE_NUMBER_TYPE_CHANGE;
351+
max.msg = '整数变小数';
352+
max.path = folder;
353+
max.value = real;
300354
}
301355
}
302356

303-
if (target !== real) { //值不同
304-
return JSONResponse.COMPARE_VALUE_CHANGE;
357+
if (max.code < JSONResponse.COMPARE_VALUE_CHANGE && target !== real) { //值不同
358+
max.code = JSONResponse.COMPARE_VALUE_CHANGE;
359+
max.msg = '值改变';
360+
max.path = folder;
361+
max.value = real;
305362
}
306363
}
307364

@@ -345,7 +402,17 @@ var JSONResponse = {
345402
}
346403

347404
return left;
348-
}
405+
},
406+
349407

408+
getAbstractPath: function (folder, name) {
409+
folder = folder == null ? '' : folder;
410+
name = name == null ? '' : name; //导致 0 变为 '' name = name || '';
411+
return StringUtil.isEmpty(folder, true) ? name : folder + '/' + name;
412+
},
413+
414+
log(msg) {
415+
// console.log(msg);
416+
}
350417

351418
}

0 commit comments

Comments
 (0)