Skip to content

Commit da32a6e

Browse files
committed
Java: MultiDataSource 更新 APIAuto
1 parent d115b14 commit da32a6e

3 files changed

Lines changed: 338 additions & 114 deletions

File tree

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

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ var JSONResponse = {
631631
delete target[codeName];
632632
real[codeName] = typeof rCode == 'undefined' ? undefined : null; // delete real[codeName];
633633
delete target.throw;
634-
real.throw = typeof rCode == 'undefined' ? rThrw : null; // delete real.throw;
634+
real.throw = typeof rThrw == 'undefined' ? rThrw : null; // delete real.throw;
635635
}
636636

637637
//可能提示语变化,也要提示
@@ -1039,7 +1039,7 @@ var JSONResponse = {
10391039
var format = target.format;
10401040
if (typeof format == 'string' && FORMAT_PRIORITIES[format] != null) {
10411041
var verifier = max.code < JSONResponse.COMPARE_FORMAT_CHANGE && StringUtil.isNotEmpty(format, true)
1042-
? FORMAT_VERIFIERS[format] : null;
1042+
&& StringUtil.isNotEmpty(real, true) ? FORMAT_VERIFIERS[format] : null;
10431043
if (typeof verifier == 'function' && verifier(real) != true) {
10441044
max.code = JSONResponse.COMPARE_FORMAT_CHANGE - (guess != true ? 0 : 1);
10451045
max.msg = '不是 ' + format + " 格式!";
@@ -1377,7 +1377,7 @@ var JSONResponse = {
13771377

13781378
var notEmpty = target.notEmpty;
13791379
log('updateStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>');
1380-
if (real != null && typeof real != 'boolean' && typeof real != 'number') {
1380+
if (notEmpty !== false && real != null && typeof real != 'boolean' && typeof real != 'number') {
13811381
notEmpty = target.notEmpty = StringUtil.isNotEmpty(real, true);
13821382
}
13831383

@@ -1648,17 +1648,18 @@ var JSONResponse = {
16481648

16491649
/**根据 APIJSON 引用赋值路径精准地获取值
16501650
*/
1651-
getValByPath: function(target, pathKeys, isTry) {
1652-
if (target == null) {
1653-
return null;
1654-
}
1655-
1656-
var tgt = target;
1657-
var depth = pathKeys == null ? 0 : pathKeys.length
1651+
getValByPath: function(target, pathKeys, isTry, isDesc, arr4Multi, isUnique) {
1652+
var depth = target == null || pathKeys == null ? 0 : pathKeys.length
16581653
if (depth <= 0) {
16591654
return target;
16601655
}
16611656

1657+
if (StringUtil.isString(pathKeys)) {
1658+
pathKeys = StringUtil.splitPath(pathKeys, false);
1659+
}
1660+
1661+
var tgt = target;
1662+
16621663
for (var i = 0; i < depth; i ++) {
16631664
if (tgt == null) {
16641665
return null;
@@ -1671,19 +1672,47 @@ var JSONResponse = {
16711672
k = decodeURI(k)
16721673

16731674
if (tgt instanceof Object) {
1674-
if (k == '') {
1675+
if (k == '') { // TODO 用 * 表示多个?
16751676
if (tgt instanceof Array) {
1676-
k = 0;
1677+
for (var j = 0; j < tgt.length; j ++) {
1678+
var ind = isDesc ? tgt.length - 1 - j : j;
1679+
var val = tgt[ind];
1680+
if (i >= depth - 1) {
1681+
if (val != null && arr4Multi == null) {
1682+
return val;
1683+
}
1684+
}
1685+
1686+
var ks = pathKeys.slice(i + 1);
1687+
var child = JSONResponse.getValByPath(val, ks, isTry, isDesc, arr4Multi, isUnique);
1688+
if (child != null && arr4Multi == null) {
1689+
return child;
1690+
}
1691+
}
1692+
16771693
} else {
1678-
ks = Object.keys(tgt);
1679-
k = ks == null ? null : ks[0];
1680-
if (k == null) {
1681-
return null;
1694+
var tks = Object.keys(tgt)
1695+
for (var j = 0; j < tks.length; j ++) {
1696+
var ind = isDesc ? tks.length - 1 - j : j;
1697+
var k2 = tks[ind];
1698+
var val = tgt[k2];
1699+
if (i >= depth - 1) {
1700+
if (val != null && arr4Multi == null) {
1701+
return val;
1702+
}
16821703
}
1704+
1705+
var ks = pathKeys.slice(i + 1);
1706+
var child = JSONResponse.getValByPath(val, ks, isTry, isDesc, arr4Multi, isUnique);
1707+
if (child != null && arr4Multi == null) {
1708+
return child;
1709+
}
1710+
}
1711+
1712+
return null;
16831713
}
16841714
}
16851715
else {
1686-
k = decodeURI(k)
16871716
if (tgt instanceof Array) {
16881717
try {
16891718
var n = Number.parseInt(k);
@@ -1707,6 +1736,10 @@ var JSONResponse = {
17071736
return null;
17081737
}
17091738

1739+
if (arr4Multi != null && ! (isUnique && arr4Multi.includes(tgt))) {
1740+
arr4Multi.push(tgt);
1741+
}
1742+
17101743
return tgt;
17111744
},
17121745

@@ -1732,7 +1765,7 @@ var JSONResponse = {
17321765
if (tgt instanceof Array) {
17331766
k = 0;
17341767
} else {
1735-
ks = Object.keys(tgt);
1768+
var ks = Object.keys(tgt);
17361769
k = ks == null ? null : ks[0];
17371770
if (k == null) {
17381771
return null;
@@ -1751,33 +1784,41 @@ var JSONResponse = {
17511784
}
17521785
}
17531786

1754-
parent = tgt;
1787+
if (tgt[k] != null) {
1788+
parent = tgt;
1789+
}
17551790
tgt = tgt[k];
1756-
continue;
1791+
// continue;
17571792
}
17581793

17591794
if (tgt == null) {
1760-
try {
1761-
var n = Number.parseInt(k);
1762-
if (Number.isSafeInteger(n)) {
1763-
k = n >= 0 ? n : n + tgt.length;
1795+
if (parent instanceof Array) {
1796+
try {
1797+
var n = Number.parseInt(k);
1798+
if (Number.isSafeInteger(n)) {
1799+
k = n >= 0 ? n : n + parent.length;
1800+
}
1801+
} catch (e) {
17641802
}
1765-
} catch (e) {
17661803
}
17671804

1768-
tgt = Number.isInteger(k) ? [] : {};
1805+
tgt = Number.isInteger(pathKeys[i + 1]) ? [] : {};
17691806
if (i == 0 && parent == null) {
17701807
parent = target = tgt;
17711808
} else {
17721809
parent[k] = tgt;
17731810
}
17741811

17751812
parent = tgt;
1776-
tgt = tgt[k];
1813+
// tgt = tgt[k];
17771814

17781815
continue;
17791816
}
17801817

1818+
if (tgt instanceof Object) {
1819+
continue
1820+
}
1821+
17811822
if (isTry != true) {
17821823
throw new Error('setValByPath 语法错误,' + k + ': value 中 value 类型应该是 Object 或 Array !');
17831824
}
@@ -2244,8 +2285,10 @@ var JSONResponse = {
22442285
switch (type) {
22452286
case 'boolean':
22462287
return 2;
2247-
case 'number':
2288+
case 'integer':
22482289
return 10;
2290+
case 'number':
2291+
return 5;
22492292
case 'string':
22502293
return 10;
22512294
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@
436436
<div class="left-bar" style="border-top: #DDD 1px solid; position: relative">
437437
<input v-show="isRandomListShow != true && isRandomSubListShow != true" id="vTestRandomCount" v-model="testRandomCount" style="margin-left: 10px; min-width: 12px; max-width: 30px; width: auto; text-align: center" type="number" />
438438
<a v-show="isRandomListShow != true && isRandomSubListShow != true" style="margin-left: 4px;"></a>
439-
<a href="javascript:void(0)" @click="isEditReqLink = true" :style="{'color': isEditReqLink ? 'red' : 'gray'}" style="font-size: medium; padding-left: 10px">请求</a><a >|</a><a href="javascript:void(0)" @click="isEditReqLink = false" :style="{'color': isEditReqLink ? 'gray' : 'red'}" style="font-size: medium">响应</a>
439+
<a v-show="isRandomListShow != true && isRandomSubListShow != true" href="javascript:void(0)" @click="onClickRandomType(false)" :style="{'color': isEditReqLink ? 'red' : 'gray'}" style="font-size: medium; padding-left: 10px">请求</a><a v-show="isRandomListShow != true && isRandomSubListShow != true" >|</a><a v-show="isRandomListShow != true && isRandomSubListShow != true" href="javascript:void(0)" @click="onClickRandomType(true)" :style="{'color': isEditReqLink ? 'gray' : 'red'}" style="font-size: medium">响应</a>
440440
<a style="display: flex;flex-grow: 1;padding-left: 10px;padding-right: 2px;font-size: medium;color: black" >{{ (isRandomListShow || StringUtil.isEmpty(randomTestTitle, true) ? '参数注入 Random Test' : randomTestTitle) + (isRandomListShow || isRandomSubListShow ? ' (' + ((isRandomListShow ? randoms : randomSubs) || []).length + ')' : '') }}
441441
<a v-show="isRandomListShow != true && (currentRemoteItem || {}).Document != null" style="padding-right: 6px;padding-top: 2px" href="javascript:void(0)" @click="showRandomList(true, (currentRemoteItem || {}).Document)">
442442
父项列表

0 commit comments

Comments
 (0)