Skip to content

Commit 275eef0

Browse files
committed
Java: MultiDataSource 内 APIAuto:JSONResponse 新增 IGNORE_KEYS 忽略字段、UPGRADE_KEYS 警告升级字段、DOWNGRADE_KEYS 警告降级字段,把 null, 0, '' 单独判空而不用于范围泛化
1 parent 9b5ef30 commit 275eef0

24 files changed

Lines changed: 153 additions & 121 deletions

File tree

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/DemoController.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
* 具体见 SpringBoot 文档
9696
* https://www.springcloud.cc/spring-boot.html#boot-features-spring-mvc
9797
* 以及 APIJSON 通用文档 3.设计规范 3.1 操作方法
98-
* https://github.com/Tencent/APIJSON/blob/master/Document.md#3.1
98+
* https://github.com/APIJSON/APIJSON/blob/main/Document.md#3.1
9999
* <br > 建议全通过HTTP POST来请求:
100100
* <br > 1.减少代码 - 客户端无需写HTTP GET,PUT等各种方式的请求代码
101101
* <br > 2.提高性能 - 无需URL encode和decode

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoFunctionParser.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
/**可远程调用的函数类,用于自定义业务逻辑处理
40-
* 具体见 https://github.com/Tencent/APIJSON/issues/101
40+
* 具体见 https://github.com/APIJSON/APIJSON/issues/101
4141
* @author Lemon
4242
*/
4343
public class DemoFunctionParser extends APIJSONFunctionParser<Long> {

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoParser.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
/**请求解析器
36-
* 具体见 https://github.com/Tencent/APIJSON/issues/38
36+
* 具体见 https://github.com/APIJSON/APIJSON/issues/38
3737
* @author Lemon
3838
*/
3939
public class DemoParser extends APIJSONParser<Long> {

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoSQLConfig.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/**SQL配置
3838
* TiDB 用法和 MySQL 一致
3939
* 具体见详细的说明文档 C.开发说明 C-1-1.修改数据库链接
40-
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
40+
* https://github.com/APIJSON/APIJSON/blob/main/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
4141
* @author Lemon
4242
*/
4343
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoSQLExecutor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
/**
5454
* SQL 执行器,支持连接池及多数据源
55-
* 具体见 https://github.com/Tencent/APIJSON/issues/151
55+
* 具体见 https://github.com/APIJSON/APIJSON/issues/151
5656
*
5757
* @author Lemon
5858
*/

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoVerifier.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
/**安全校验器,校验请求参数、角色与权限等
23-
* 具体见 https://github.com/Tencent/APIJSON/issues/12
23+
* 具体见 https://github.com/APIJSON/APIJSON/issues/12
2424
* @author Lemon
2525
*/
2626
public class DemoVerifier extends APIJSONVerifier<Long> {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
集合 文档、测试、Mock、调试、管理 的一站式体验,还有 **AI 问答** 和一键 格式化、注释/取消注释 等高效快捷键。<br />
2222
在常用功能上远超 Postman, Swagger, YApi 等各种 开源、商业 的 API 文档/测试 工具,并能一键导入用例和文档。<br />
2323
支持 GET, POST, PUT, PATCH, DELETE, HEAD 等各种 HTTP Method 及 Content-Type, URL /{Path}/{Variable}。<br />
24-
不仅适用于 RESTful、类 RESTful、GRPC 的 API,还是腾讯 [APIJSON](https://github.com/Tencent/APIJSON) 官方建议的文档与测试工具。<br />
24+
不仅适用于 RESTful、类 RESTful、GRPC 的 API,还是腾讯 [APIJSON](https://github.com/APIJSON/APIJSON) 官方建议的文档与测试工具。<br />
2525
腾讯内部用户包括 IEG 互动娱乐事业群、TEG 技术工程事业群、CSIG 云与智慧事业群 的多个部门及团队, <br />
2626
外部用户包含 华为、工商银行某地分行、500 强上市公司传音、跨境电商巨头 SHEIN、行业领头羊社保科技 等。
2727

@@ -248,7 +248,7 @@ https://github.com/TommyLemon/APIAuto/issues/9
248248

249249
#### 2.没有生成文档
250250
右上角设置项与数据库实际配置不一致 等 <br />
251-
https://github.com/Tencent/APIJSON/issues/85
251+
https://github.com/APIJSON/APIJSON/issues/85
252252

253253
#### 3.托管服务器访问不了
254254
不能代理接口、不能展示文档、不能对断言结果纠错 等 <br />
@@ -295,13 +295,13 @@ https://github.com/TommyLemon/APIAuto/issues
295295
![image](https://github.com/user-attachments/assets/c4aa8573-f8b3-4973-8c37-29677c06ac3b)
296296

297297
如果有什么问题或建议可以 [提 issue](https://github.com/TommyLemon/APIAuto/issues),交流技术,分享经验。<br >
298-
如果你解决了某些 bug,或者新增了一些功能,欢迎 [提 PR 贡献代码](https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md),感激不尽。
298+
如果你解决了某些 bug,或者新增了一些功能,欢迎 [提 PR 贡献代码](https://github.com/APIJSON/APIJSON/blob/main/CONTRIBUTING.md),感激不尽。
299299
<br />
300300
<br />
301301

302302
### 生态项目
303303

304-
[APIJSON](https://github.com/Tencent/APIJSON) 🏆 腾讯实时 零代码、全功能、强安全 ORM 库 🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构
304+
[APIJSON](https://github.com/APIJSON/APIJSON) 🏆 腾讯实时 零代码、全功能、强安全 ORM 库 🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构
305305

306306
[CVAuto](https://github.com/TommyLemon/CVAuto) 👁 零代码零标注 CV AI 自动化测试平台 🚀 免除大量人工画框和打标签等,直接快速测试 CV 计算机视觉 AI 图像识别算法
307307

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

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ var JSONResponse = {
185185
KEY_MSG: 'msg',
186186
KEY_THROW: 'throw',
187187
CODE_SUCCESS: 200,
188+
IGNORE_KEYS: ['traceId', 'trace:stack', 'debug:info|help'],
189+
UPGRADE_KEYS: ['price', 'amount', 'money', 'cash', 'spend', 'cost', 'income', 'outgoing', 'borrow', 'lend', 'gold', 'coin', 'diamond', 'credit', 'budget', 'quantity', 'balance'],
190+
DOWNGRADE_KEYS: ['id', 'ID', 'traceId', 'trace_id', 'date', 'time', 'datetime', 'date_time', 'dateTime', 'timestamp', 'create_time', 'update_time', 'created_at', 'updated_at', 'createTime', 'updateTime', 'createdAt', 'updatedAt'],
191+
188192
/**是否成功
189193
* @param code
190194
* @return
@@ -917,7 +921,9 @@ var JSONResponse = {
917921
};
918922
}
919923

920-
if (notEmpty == true && typeof real != 'boolean' && typeof real != 'number' && StringUtil.isEmpty(real, true)) { // 空
924+
var realType = JSONResponse.getType(real);
925+
926+
if (notEmpty == true && (real === 0 || (typeof real != 'boolean' && CodeUtil.isTypeMatch('number', realType) && StringUtil.isEmpty(real, true)))) { // 空
921927
log('compareWithStandard notEmpty == true && StringUtil.isEmpty(real, true) >> return COMPARE_VALUE_EMPTY');
922928
return {
923929
code: JSONResponse.COMPARE_VALUE_EMPTY,
@@ -934,7 +940,6 @@ var JSONResponse = {
934940
value: null //导致正确时也显示 real
935941
};
936942

937-
var realType = JSONResponse.getType(real);
938943
if (StringUtil.isEmpty(realType) || ['null', 'undefined'].indexOf(realType) >= 0) {
939944
realType = null;
940945
}
@@ -1067,13 +1072,31 @@ var JSONResponse = {
10671072
var valueCompare = max.code >= JSONResponse.COMPARE_VALUE_CHANGE
10681073
? 0 : JSONResponse.compareValue(valueLevel, values, real, target.trend, target.repeat);
10691074

1075+
var isNum = CodeUtil.isTypeMatch('number', type)
1076+
1077+
if (isNum) {
1078+
if (JSONResponse.UPGRADE_KEYS.includes(folder)) {
1079+
valueCompare++;
1080+
} else if (JSONResponse.DOWNGRADE_KEYS.includes(folder)) {
1081+
valueCompare--;
1082+
} else if (folder.includes('/')) {
1083+
var keys = StringUtil.splitPath(folder);
1084+
var key = keys == null || keys.length <= 0 ? null : keys[keys.length - 1];
1085+
if (StringUtil.isNotEmpty(key) && !StringUtil.isNumber(key)) {
1086+
if (JSONResponse.UPGRADE_KEYS.includes(key)) {
1087+
valueCompare++;
1088+
} else if (JSONResponse.DOWNGRADE_KEYS.includes(key)) {
1089+
valueCompare--;
1090+
}
1091+
}
1092+
}
1093+
}
1094+
10701095
if (valueCompare > 0) {
10711096
max.code = valueCompare;
10721097
max.path = folder;
10731098
max.value = real;
10741099

1075-
var isNum = CodeUtil.isTypeMatch('number', type)
1076-
10771100
if (isNum && valueCompare == JSONResponse.COMPARE_VALUE_REPEAT && (target.repeat == null || target.repeat <= 0)
10781101
&& values != null && values.indexOf(real) >= 0) {
10791102
max.msg = '值与历史值重复:' + real;
@@ -1377,16 +1400,21 @@ var JSONResponse = {
13771400

13781401
var notEmpty = target.notEmpty;
13791402
log('updateStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>');
1380-
if (notEmpty !== false && real != null && typeof real != 'boolean' && typeof real != 'number') {
1381-
notEmpty = target.notEmpty = StringUtil.isNotEmpty(real, true);
1403+
var rtype = JSONResponse.getType(real);
1404+
1405+
if (notEmpty !== false) {
1406+
if (CodeUtil.isTypeMatch('number', rtype)) { // real === 0) {
1407+
notEmpty = target.notEmpty = real === 0 ? false : (real < -1 || real > 1 ? true : notEmpty);
1408+
} else if (real != null && typeof real != 'boolean') {
1409+
notEmpty = target.notEmpty = StringUtil.isNotEmpty(real, true);
1410+
}
13821411
}
13831412

13841413
var type = target.type;
13851414
if (type == null || type == 'undefined') {
13861415
target.type = type = null;
13871416
}
13881417

1389-
var rtype = JSONResponse.getType(real);
13901418
if ((rtype == null || real == null) && StringUtil.isEmpty(type, true) && StringUtil.isNotEmpty(key, true)) {
13911419
target.guess = true;
13921420
if (StringUtil.isBoolKey(key)) {
@@ -1490,7 +1518,6 @@ var JSONResponse = {
14901518
}
14911519
log('updateStandard type = target.type = getType(real) = ' + type + ' >>');
14921520

1493-
14941521
var lengthLevel = target.lengthLevel;
14951522
var lengths = target.lengths;
14961523
log('updateStandard lengthLevel = target.lengthLevel = ' + lengthLevel + ' >>');
@@ -1629,16 +1656,18 @@ var JSONResponse = {
16291656
}
16301657
}
16311658

1632-
if (values == null) {
1633-
values = [];
1634-
}
1635-
if (valueLevel < 1 && type == 'number' && ! Number.isSafeInteger(real)) { //double 1.23
1636-
valueLevel = 1;
1637-
}
1638-
target.values = values;
1659+
if (! [null, 0, ''].includes(real)) {
1660+
if (values == null) {
1661+
values = [];
1662+
}
1663+
if (valueLevel < 1 && CodeUtil.isTypeMatch('number', type) && ! Number.isSafeInteger(real)) { //double 1.23
1664+
valueLevel = 1;
1665+
}
1666+
target.values = values;
16391667

1640-
target = JSONResponse.setValue(target, JSONResponse.getLength(real), lengthLevel == null ? 1 : lengthLevel, lengths, true, true);
1641-
target = JSONResponse.setValue(target, real, valueLevel, values, false, ignoreTrend);
1668+
target = JSONResponse.setValue(target, JSONResponse.getLength(real), lengthLevel == null ? 1 : lengthLevel, lengths, true, true);
1669+
target = JSONResponse.setValue(target, real, valueLevel, values, false, ignoreTrend);
1670+
}
16421671
}
16431672

16441673
log('\nupdateStandard >> return target = ' + JSON.stringify(target, null, ' ') + '\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n\n\n\n\n');

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,19 @@
8989
</span>
9090
<a v-show="isDelayShow" >2s</a>
9191

92-
93-
<iframe v-show="User.id == null || User.id <= 0" src="https://ghbtns.com/github-btn.html?user=Tencent&amp;repo=APIJSON&amp;type=star&amp;count=true&amp;size=small" frameborder="0" scrolling="0" width="160px" height="18px"></iframe>
92+
<iframe v-show="User.id == null || User.id <= 0" src="https://ghbtns.com/github-btn.html?user=Tencent&amp;repo=APIJSON&amp;type=star&amp;count=true&amp;size=small" frameborder="0" scrolling="0" width="120px" height="18px"></iframe>
9493

9594
<!--只用60%避免拦截左右两侧View的触摸事件-->
9695
<div style="width: 40%;height: 100%;left: 30%;display: inline-block;text-align: center;position: fixed;padding-top: 10px">
97-
<a style="font-size: large;margin-left: 10px;margin-right: 10px;color: silver" href="https://github.com/Tencent/APIJSON/blob/master/Document.md" target="_blank" >文档</a>
96+
<a style="font-size: large;margin-left: 10px;margin-right: 10px;color: silver" href="https://github.com/APIJSON/APIJSON/blob/main/Document.md" target="_blank" >文档</a>
9897
<a style="font-size: large;margin-left: 10px;margin-right: 10px;color: silver" href="https://search.bilibili.com/all?keyword=APIJSON" target="_blank" >视频</a>
9998
<a style="font-size: large;margin-left: 10px;margin-right: 10px;color: silver" href="https://github.com/search?o=desc&q=apijson&s=stars&type=Repositories" target="_blank" >生态</a>
10099
</div>
101100

102101
<div class="top-right">
103-
<a style="padding: 6px" v-show="User.id == null || User.id <= 0" href="https://git.code.tencent.com/Tencent_Open_Source/APIJSON" target="_blank" >
104-
<img class="ui inline black image" height="24" src="http://apijson.cn/images/tencent_open_logo.png">
105-
</a>
102+
<!-- <a style="padding: 6px" v-show="User.id == null || User.id <= 0" href="https://git.code.tencent.com/Tencent_Open_Source/APIJSON" target="_blank" >-->
103+
<!-- <img class="ui inline black image" height="24" src="http://apijson.cn/images/tencent_open_logo.png">-->
104+
<!-- </a>-->
106105

107106
<a style="padding: 6px" v-show="User.id == null || User.id <= 0" href="https://gitee.com/Tencent/APIJSON" target="_blank">
108107
<img class="ui inline black image" height="24" src="https://gitee.com/logo-black.svg?20171024" width="60">

0 commit comments

Comments
 (0)