Skip to content

Commit

Permalink
新增历史请求记录;新增管理员账号;新增配置schema和托管服务器;优化自动化接口回归测试;优化自动注释;新增文档视频源码等入口;修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Oct 31, 2018
1 parent 28b017e commit d8ce819
Show file tree
Hide file tree
Showing 8 changed files with 1,028 additions and 338 deletions.
89 changes: 58 additions & 31 deletions apijson/CodeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ var CodeUtil = {
else {
if (line.endsWith('}')) {
if (line.endsWith('{}')) { //对象,判断是不是Table,再加对应的注释
names[depth] = key;
comment = CodeUtil.getComment4Request(tableList, null, key, null, method);
}
else {
Expand Down Expand Up @@ -225,20 +224,22 @@ var CodeUtil = {
const isTable = isSmart && JSONObject.isTableKey(JSONResponse.getTableName(key));

const column = isTable ? value['@column'] : null;
const order = isTable ? value['@order'] : null;
const group = isTable ? value['@group'] : null;
const having = isTable ? value['@having'] : null;
const order = isTable ? value['@order'] : null;
const combine = isTable ? value['@combine'] : null;
const schema = isTable ? value['@schema'] : null;
const database = isTable ? value['@database'] : null;
const role = isTable ? value['@role'] : null;

if (isTable) {
delete value['@column'];
delete value['@order'];
delete value['@group'];
delete value['@having'];
delete value['@order'];
delete value['@combine'];
delete value['@schema'];
delete value['@database'];
delete value['@role'];
}

Expand All @@ -247,11 +248,12 @@ var CodeUtil = {
const name = CodeUtil.getTableKey(JSONResponse.getSimpleName(key));
if (isTable) {
s = column == null ? s : s + '\n' + name + '.setColumn(' + CodeUtil.getJavaValue(name, key, column) + ');';
s = order == null ? s : s + '\n' + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
s = group == null ? s : s + '\n' + name + '.setGroup(' + CodeUtil.getJavaValue(name, key, group) + ');';
s = having == null ? s : s + '\n' + name + '.setHaving(' + CodeUtil.getJavaValue(name, key, having) + ');';
s = order == null ? s : s + '\n' + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
s = combine == null ? s : s + '\n' + name + '.setCombine(' + CodeUtil.getJavaValue(name, key, combine) + ');';
s = schema == null ? s : s + '\n' + name + '.setSchema(' + CodeUtil.getJavaValue(name, key, schema) + ');';
s = database == null ? s : s + '\n' + name + '.setDatabase(' + CodeUtil.getJavaValue(name, key, database) + ');';
s = role == null ? s : s + '\n' + name + '.setRole(' + CodeUtil.getJavaValue(name, key, role) + ');';
}

Expand All @@ -270,6 +272,18 @@ var CodeUtil = {
if (key == 'version') {
return '\n' + parentKey + '.setVersion(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
if (key == 'format') {
return '\n' + parentKey + '.setFormat(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
if (key == '@schema') {
return '\n' + parentKey + '.setSchema(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
if (key == '@database') {
return '\n' + parentKey + '.setDatabase(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
if (key == '@role') {
return '\n' + parentKey + '.setRole(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
}
return '\n' + parentKey + '.put("' + key + '", ' + CodeUtil.getJavaValue(name, key, value) + ');';
}
Expand Down Expand Up @@ -827,6 +841,7 @@ var CodeUtil = {
OWNER: '拥有者',
ADMIN: '管理员'
},
REQUEST_DATABASE_KEYS: ['MYSQL', 'POSTGRESQL', 'ORACLE'],

/**获取请求JSON的注释
* @param tableList
Expand Down Expand Up @@ -875,17 +890,17 @@ var CodeUtil = {
if (JSONObject.isArrayKey(name)) {
switch (key) {
case 'count':
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('最多数量', false, ' ');
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('最多数量: 例如 5 10 20 ...', false, ' ');
case 'page':
if (CodeUtil.getType4Request(value) != 'number') {
return ' ! value必须是Number类型!';
}
return value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码', false, ' ');
return value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码: 例如 0 1 2 ...', false, ' ');
case 'query':
var query = CodeUtil.QUERY_TYPES[value];
return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-数据 1-总数 2-全部', false, ' ');
case 'join':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('多表连接:LEFT JOIN < ,RIGHT JOIN > ,INNER JOIN & | ! ', false, ' ');
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('多表连接:例如 &/User/id@,</Comment/momentId@,...', false, ' ');
}
return '';
}
Expand All @@ -894,29 +909,32 @@ var CodeUtil = {
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);

if (JSONObject.isTableKey(objName)) {
switch (key) {
case '@column':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段:例如 id,name;json_length(contactIdList):contactCount;...', false, ' ');
case '@group':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式:例如 userId,momentId,...', false, ' ');
case '@having':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('SQL函数:例如 max(id)>100;sum(balance)<=10000;...', false, ' ');
case '@order':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序,例如 name+,date-,...', false, ' ');
case '@combine':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合:例如 name?,|tag?,&id{},!id,...', false, ' ');
case '@schema':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间:例如 sys apijson ...', false, ' ');
case '@database':
try {
value = value.substring(1, value.length - 1).toUpperCase();
} catch (e) {}
return CodeUtil.REQUEST_DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.REQUEST_DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库:例如 MYSQL POSTGRESQL ORACLE ...', false, ' ');
case '@role':
try {
value = value.substring(1, value.length - 1).toUpperCase();
} catch (e) {}
var role = CodeUtil.REQUEST_ROLE[value];
return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.REQUEST_ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
}
if (key.startsWith('@')) {
switch (key) {
case '@column':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段:例如 id,name,json_length(contactIdList):contactCount...', false, ' ');
case '@order':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序,例如 name+,date-,...', false, ' ');
case '@group':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式:例如 userId', false, ' ');
case '@having':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('SQL函数:例如 max(id)>100,sum(balance)<=10000,...', false, ' ');
case '@combine':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合:例如 name?,|tag?,&id{},!id,...', false, ' ');
case '@schema':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('数据库:例如 sys', false, ' ');
case '@correct':
return value != null ? ' ! value必须是Object类型!' : CodeUtil.getComment('字段校正', false, ' ');
case '@role':
try {
value = value.substring(1, value.length - 1).toUpperCase();
} catch (e) {}
var role = CodeUtil.REQUEST_ROLE[value];
return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.REQUEST_ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
}
return '';
}
var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method);
Expand All @@ -930,12 +948,21 @@ var CodeUtil = {
if (method == 'GET' || method == 'HEAD') {
return '';
}
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('请求密钥', false, ' ');
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('请求密钥:例如 User Comment[] Privacy-CIRCLE ...', false, ' ');
case 'version':
if (method == 'GET' || method == 'HEAD') {
return '';
}
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('版本号', false, ' ');
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('版本号: 例如 1 2 3 ...', false, ' ');
case 'format':
return CodeUtil.getType4Request(value) != 'boolean' ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否', false, ' ');
case '@schema':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间:例如 sys apijson ...', false, ' ');
case '@database':
try {
value = value.substring(1, value.length - 1).toUpperCase();
} catch (e) {}
return CodeUtil.REQUEST_DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.REQUEST_DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库:例如 MYSQL POSTGRESQL ORACLE ...', false, ' ');
case '@role':
try {
value = value.substring(1, value.length - 1).toUpperCase();
Expand Down
2 changes: 1 addition & 1 deletion apijson/JSONRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function format(json) {
}

function log(tag, msg) {
console.log(tag + '.' + msg);
//console.log(tag + '.' + msg);
}

/**将json字符串转为JSON对象
Expand Down
115 changes: 91 additions & 24 deletions apijson/JSONResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ var JSONResponse = {
COMPARE_NO_STANDARD: -1,
COMPARE_EQUAL: 0,
COMPARE_KEY_MORE: 1,
COMPARE_LENGTH_CHANGE: 2,
COMPARE_VALUE_CHANGE: 2,
COMPARE_KEY_LESS: 3,
COMPARE_TYPE_CHANGE: 4,
Expand All @@ -207,22 +208,38 @@ var JSONResponse = {
3-对象缺少字段/整数变小数,黄色;
4-code/值类型 改变,红色;
*/
compareResponse: function(target, real) {
compareResponse: function(target, real, folder, isMachineLearning) {
if (target == null || target.code == null) {
return JSONResponse.COMPARE_NO_STANDARD; //未上传对比标准(正确的结果)
return {
code: JSONResponse.COMPARE_NO_STANDARD, //未上传对比标准
msg: '没有校验标准!',
path: folder == null ? '' : folder
};
}
if (target.code != real.code) {
return JSONResponse.COMPARE_CODE_CHANGE;
return {
code: JSONResponse.COMPARE_CODE_CHANGE,
msg: '状态码改变!',
path: folder == null ? '' : folder
};
}

var tCode = target.code;
var rCode = real.code;

delete target.code;
delete real.code;

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

return JSONResponse.compare(target, real);
var result = JSONResponse.compareWithBefore(target, real, folder);

target.code = tCode;
real.code = rCode;

return result;
},

/**测试compare: 对比 新的请求与上次请求的结果
Expand All @@ -232,76 +249,116 @@ var JSONResponse = {
3-缺少字段/整数变小数,黄色;
4-类型/code 改变,红色;
*/
compare: function(target, real) {
compareWithBefore: function(target, real, folder) {
folder = folder == null ? '' : folder;

if (target == null) {
return real == null ? JSONResponse.COMPARE_EQUAL : JSONResponse.COMPARE_KEY_MORE;
return {
code: real == null ? JSONResponse.COMPARE_EQUAL : JSONResponse.COMPARE_KEY_MORE,
msg: real == null ? '结果正确' : '是新增的',
path: real == null ? '' : folder,
value: real
};
}
if (real == null) { //少了key
return JSONResponse.COMPARE_KEY_LESS;
return {
code: JSONResponse.COMPARE_KEY_LESS,
msg: '是缺少的',
path: folder,
value: real
};
}

var type = typeof target;
if (type != typeof real) { //类型改变
return JSONResponse.COMPARE_TYPE_CHANGE;
return {
code: JSONResponse.COMPARE_TYPE_CHANGE,
msg: '值改变',
path: folder,
value: real
};
}

var max = JSONResponse.COMPARE_EQUAL;
var each = JSONResponse.COMPARE_EQUAL;
// var max = JSONResponse.COMPARE_EQUAL;
// var each = JSONResponse.COMPARE_EQUAL;

var max = {
code: JSONResponse.COMPARE_EQUAL,
msg: '结果正确',
path: '', //导致正确时也显示 folder,
value: null //导致正确时也显示 real
};

var each;

if (target instanceof Array) { // JSONArray
var all = target[0];
for (var i = 1; i < length; i++) { //合并所有子项, Java类型是稳定的,不会出现两个子项间同名字段对应值类型不一样
all = JSONResponse.deepMerge(all, target[i]);
}
//下载需要看源JSON real = [all];

each = JSONResponse.compare(target[0], all);
each = JSONResponse.compareWithBefore(target[0], all, JSONResponse.getAbstractPath(folder, i));

if (max < each) {
if (max.code < each.code) {
max = each;
}

if (max < JSONResponse.COMPARE_VALUE_CHANGE) {
if (max.code < JSONResponse.COMPARE_VALUE_CHANGE) {
if (target.length != real.length || (JSON.stringify(target) != JSON.stringify(real))) {
max = JSONResponse.COMPARE_VALUE_CHANGE;
max.code = JSONResponse.COMPARE_VALUE_CHANGE;
max.msg = '值改变';
max.path = folder;
max.value = real;
}
}
}
else if (target instanceof Object) { // JSONObject
var tks = Object.keys(target);
var key;
for (var i = 0; i< tks.length; i++) { //遍历并递归下一层
for (var i = 0; i < tks.length; i++) { //遍历并递归下一层
key = tks[i];
if (key == null) {
continue;
}

each = JSONResponse.compare(target[key], real[key]);
if (max < each) {
each = JSONResponse.compareWithBefore(target[key], real[key], JSONResponse.getAbstractPath(folder, key));
if (max.code < each.code) {
max = each;
}
if (max >= JSONResponse.COMPARE_TYPE_CHANGE) {
if (max.code >= JSONResponse.COMPARE_TYPE_CHANGE) {
break;
}
}


if (max < JSONResponse.COMPARE_KEY_MORE) { //多出key
if (max.code < JSONResponse.COMPARE_KEY_MORE) { //多出key
for (var k in real) {
if (k != null && tks.indexOf(k) < 0) {
max = JSONResponse.COMPARE_KEY_MORE;
max.code = JSONResponse.COMPARE_KEY_MORE;
max.msg = '是新增的';
max.path = JSONResponse.getAbstractPath(folder, k);
max.value = real[k];
break;
}
}
}
}
else { // Boolean, Number, String
if (type == 'number') { //数字类型由整数变为小数
if (String(target).indexOf('.') < 0 && String(real).indexOf('.') >= 0) {
return JSONResponse.COMPARE_NUMBER_TYPE_CHANGE;
max.code = JSONResponse.COMPARE_NUMBER_TYPE_CHANGE;
max.msg = '整数变小数';
max.path = folder;
max.value = real;
}
}

if (target !== real) { //值不同
return JSONResponse.COMPARE_VALUE_CHANGE;
if (max.code < JSONResponse.COMPARE_VALUE_CHANGE && target !== real) { //值不同
max.code = JSONResponse.COMPARE_VALUE_CHANGE;
max.msg = '值改变';
max.path = folder;
max.value = real;
}
}

Expand Down Expand Up @@ -345,7 +402,17 @@ var JSONResponse = {
}

return left;
}
},


getAbstractPath: function (folder, name) {
folder = folder == null ? '' : folder;
name = name == null ? '' : name; //导致 0 变为 '' name = name || '';
return StringUtil.isEmpty(folder, true) ? name : folder + '/' + name;
},

log(msg) {
// console.log(msg);
}

}
Loading

0 comments on commit d8ce819

Please sign in to comment.