@voxgig/apidef 8.23.0 → 8.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder/entity/entity.d.ts +2 -1
- package/dist/builder/entity/entity.js +14 -11
- package/dist/builder/entity/entity.js.map +1 -1
- package/dist/guide/guide.js +5 -2
- package/dist/guide/guide.js.map +1 -1
- package/dist/guide/heuristic01.d.ts +2 -1
- package/dist/guide/heuristic01.js +232 -85
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/transform/args.d.ts +4 -1
- package/dist/transform/args.js +42 -13
- package/dist/transform/args.js.map +1 -1
- package/dist/transform/body.d.ts +19 -2
- package/dist/transform/body.js +189 -15
- package/dist/transform/body.js.map +1 -1
- package/dist/transform/field.d.ts +3 -1
- package/dist/transform/field.js +159 -87
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/operation.js +77 -24
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform/select.js +10 -4
- package/dist/transform/select.js.map +1 -1
- package/dist/transform/top.d.ts +2 -1
- package/dist/transform/top.js +50 -3
- package/dist/transform/top.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +9 -1
- package/dist/utility.js +139 -13
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/src/builder/entity/entity.ts +17 -15
- package/src/guide/guide.ts +5 -3
- package/src/guide/heuristic01.ts +292 -93
- package/src/transform/args.ts +50 -14
- package/src/transform/body.ts +231 -15
- package/src/transform/field.ts +190 -88
- package/src/transform/operation.ts +97 -26
- package/src/transform/select.ts +13 -4
- package/src/transform/top.ts +59 -3
- package/src/utility.ts +169 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.answeredRefs = answeredRefs;
|
|
4
|
+
exports.arrayBodyField = arrayBodyField;
|
|
4
5
|
exports.distinctRecord = distinctRecord;
|
|
5
6
|
exports.distinctShare = distinctShare;
|
|
6
7
|
exports.heuristic01 = heuristic01;
|
|
@@ -16,6 +17,7 @@ const ordu_1 = require("ordu");
|
|
|
16
17
|
const jostraca_1 = require("jostraca");
|
|
17
18
|
const struct_1 = require("@voxgig/struct");
|
|
18
19
|
const utility_1 = require("../utility");
|
|
20
|
+
const body_1 = require("../transform/body");
|
|
19
21
|
const utility_2 = require("../utility");
|
|
20
22
|
const jostraca_2 = require("jostraca");
|
|
21
23
|
const entity_1 = require("../transform/entity");
|
|
@@ -73,9 +75,10 @@ async function heuristic01(ctx) {
|
|
|
73
75
|
MeasureAnswered,
|
|
74
76
|
{ select: selectAllMethods, apply: MeasureSharing },
|
|
75
77
|
MeasureShared,
|
|
78
|
+
{ select: selectAllMethods, apply: [ResolveEntityComponent, MeasureTagItems] },
|
|
79
|
+
{ select: selectAllMethods, apply: MeasureClaims },
|
|
76
80
|
{
|
|
77
81
|
select: selectAllMethods, apply: [
|
|
78
|
-
ResolveEntityComponent,
|
|
79
82
|
ResolveEntityName,
|
|
80
83
|
RenameParams,
|
|
81
84
|
FindActions,
|
|
@@ -151,6 +154,12 @@ function Prepare(spec) {
|
|
|
151
154
|
envelopePaths: {},
|
|
152
155
|
sharing: { routes: [], records: {}, yields: {} },
|
|
153
156
|
recordResources: {},
|
|
157
|
+
tagItems: {},
|
|
158
|
+
claims: {},
|
|
159
|
+
claimowner: {},
|
|
160
|
+
claimrecord: {},
|
|
161
|
+
pathowner: {},
|
|
162
|
+
recordowner: {},
|
|
154
163
|
entity: {
|
|
155
164
|
count: {
|
|
156
165
|
seen: 0,
|
|
@@ -318,8 +327,13 @@ function MeasureShared(spec) {
|
|
|
318
327
|
sharing.yields[key] = true;
|
|
319
328
|
}
|
|
320
329
|
}
|
|
330
|
+
// One list for every pass, so a method keeps the component resolved for it.
|
|
321
331
|
function selectAllMethods(_source, spec) {
|
|
322
332
|
const ctx = spec.ctx;
|
|
333
|
+
const work = spec.data.work;
|
|
334
|
+
if (null != work.methods) {
|
|
335
|
+
return work.methods;
|
|
336
|
+
}
|
|
323
337
|
let caught = { methods: [] };
|
|
324
338
|
for (const [path, pdef] of (0, utility_2.sortedEntries)(ctx.def.paths)) {
|
|
325
339
|
for (const [m, mdef] of (0, utility_2.sortedEntries)(pdef)) {
|
|
@@ -361,7 +375,49 @@ function selectAllMethods(_source, spec) {
|
|
|
361
375
|
return 0;
|
|
362
376
|
}
|
|
363
377
|
});
|
|
364
|
-
|
|
378
|
+
work.methods = caught.methods;
|
|
379
|
+
return work.methods;
|
|
380
|
+
}
|
|
381
|
+
// The collections each tag gathers item routes from, before any is named, with
|
|
382
|
+
// the parameters of each collection's item routes.
|
|
383
|
+
function MeasureTagItems(spec) {
|
|
384
|
+
const work = spec.data.work;
|
|
385
|
+
const mdesc = spec.node.val;
|
|
386
|
+
const parts = work.pathmap[mdesc.path].parts;
|
|
387
|
+
const collection = tagItemCollection(spec.data, mdesc, parts);
|
|
388
|
+
if (null != collection) {
|
|
389
|
+
const cmp = mdesc.MethodEntity.cmp;
|
|
390
|
+
const items = work.tagItems[cmp] = work.tagItems[cmp] ?? {};
|
|
391
|
+
items[collection] = items[collection] ?? {};
|
|
392
|
+
items[collection][parts.filter(isParam)
|
|
393
|
+
.map((part) => (0, utility_2.canonizeParam)(part.slice(1, -1))).sort().join(',')] = true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// The name each route takes by its path and component, and its stored form,
|
|
397
|
+
// found before any route is named so an item route sees one sorting after it.
|
|
398
|
+
// The rules run on copies. A verb takes its parent's claim; an item route its
|
|
399
|
+
// collection names makes none, so a verb on one claims the route's segment.
|
|
400
|
+
function MeasureClaims(spec) {
|
|
401
|
+
const data = spec.data;
|
|
402
|
+
const work = data.work;
|
|
403
|
+
const mdesc = spec.node.val;
|
|
404
|
+
const parts = work.pathmap[mdesc.path].parts;
|
|
405
|
+
if (null != collectionNaming(data, mdesc, parts, work.claimrecord)) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const ment = { ...(mdesc.MethodEntity ?? makeMethodEntityDesc({})) };
|
|
409
|
+
const name = pathEntityName(data, { ...mdesc, MethodEntity: ment }, parts, matchEntityPath(parts), work.claimowner, []);
|
|
410
|
+
if (null != name) {
|
|
411
|
+
const claim = (0, utility_2.resplitFromCmp)(name, ment.cmp, []);
|
|
412
|
+
const stored = (0, utility_2.ensureMinEntityName)(claim, {});
|
|
413
|
+
for (const key of [claim, stored]) {
|
|
414
|
+
const claims = work.claims[key] = work.claims[key] ?? {};
|
|
415
|
+
claims[mdesc.path] = true;
|
|
416
|
+
}
|
|
417
|
+
const owners = work.claimowner[mdesc.path] = work.claimowner[mdesc.path] ?? {};
|
|
418
|
+
owners[mdesc.method] = claim;
|
|
419
|
+
markRecordOwner(work.claimrecord, mdesc.path, parts, ment, stored);
|
|
420
|
+
}
|
|
365
421
|
}
|
|
366
422
|
function ResolveEntityComponent(spec) {
|
|
367
423
|
const guide = spec.data.guide;
|
|
@@ -504,35 +560,17 @@ function ResolveEntityName(spec) {
|
|
|
504
560
|
ment = mdesc.MethodEntity;
|
|
505
561
|
}
|
|
506
562
|
why_path.push(...(ment.why_cmp ?? []));
|
|
507
|
-
let entname;
|
|
508
563
|
const pm = matchEntityPath(parts);
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
entname = entityPathMatch_tpe(data, pm, mdesc, why_path);
|
|
514
|
-
}
|
|
515
|
-
else if ('p/t/' === pm?.expr) {
|
|
516
|
-
entname = entityPathMatch_pte(data, pm, mdesc, why_path);
|
|
517
|
-
}
|
|
518
|
-
else if ('t/' === pm?.expr) {
|
|
519
|
-
entname = entityPathMatch_te(data, pm, mdesc, why_path);
|
|
520
|
-
}
|
|
521
|
-
else if ('t/p/p' === pm?.expr) {
|
|
522
|
-
entname = entityPathMatch_tpp(data, pm, mdesc, why_path);
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
entname = inferEntityName(mdesc, parts, why_path);
|
|
526
|
-
if (null == entname) {
|
|
527
|
-
work.entity.count.unresolved++;
|
|
528
|
-
entname = 'entity' + work.entity.count.unresolved;
|
|
529
|
-
}
|
|
564
|
+
let entname = pathEntityName(data, mdesc, parts, pm, work.pathowner, why_path);
|
|
565
|
+
if (null == entname) {
|
|
566
|
+
work.entity.count.unresolved++;
|
|
567
|
+
entname = 'entity' + work.entity.count.unresolved;
|
|
530
568
|
}
|
|
531
569
|
entname = (0, utility_2.resplitFromCmp)(entname, ment.cmp, why_path);
|
|
532
|
-
const
|
|
533
|
-
if (null !=
|
|
534
|
-
why_path.push('
|
|
535
|
-
entname =
|
|
570
|
+
const item = itemOfCollection(data, mdesc, parts);
|
|
571
|
+
if (null != item) {
|
|
572
|
+
why_path.push(item.why + '=' + item.name);
|
|
573
|
+
entname = item.name;
|
|
536
574
|
}
|
|
537
575
|
// Keep the pre-truncation name so a truncated-name collision can tell a
|
|
538
576
|
// re-encounter of the SAME origin (merge) from a genuinely different one
|
|
@@ -562,22 +600,43 @@ function ResolveEntityName(spec) {
|
|
|
562
600
|
// split across entities by method (a PUT answering with a one-off
|
|
563
601
|
// acknowledgement is named after it), and the parent of a verb is the
|
|
564
602
|
// entity a read of the item returns.
|
|
565
|
-
work.pathowner = work.pathowner ?? {};
|
|
566
603
|
work.pathowner[pathStr] = work.pathowner[pathStr] ?? {};
|
|
567
604
|
work.pathowner[pathStr][methodName] = entname;
|
|
568
|
-
|
|
569
|
-
// the path's last segment gives.
|
|
570
|
-
const last = parts.filter((part) => !isParam(part)).pop();
|
|
571
|
-
work.recordowner = work.recordowner ?? {};
|
|
572
|
-
if (null == work.recordowner[pathStr] && isSchemaRef(ment.ref) &&
|
|
573
|
-
entname === ment.cmp && null != last && entname === (0, utility_2.canonize)(last)) {
|
|
574
|
-
work.recordowner[pathStr] = entname;
|
|
575
|
-
}
|
|
605
|
+
markRecordOwner(work.recordowner, pathStr, parts, ment, entname);
|
|
576
606
|
// Same guard, same reason: the formatting is the cost, not the call.
|
|
577
607
|
if ((0, utility_2.debugpathOn)()) {
|
|
578
608
|
(0, utility_2.debugpath)(pathStr, methodName, 'RESOLVE-ENTITY-NAME', (0, utility_2.formatJSONIC)({ entdesc, ment }, { hsepd: 0, $: true, color: true }));
|
|
579
609
|
}
|
|
580
610
|
}
|
|
611
|
+
// The name a method's path shape and component give it, or null where neither
|
|
612
|
+
// does. A verb on a parent takes the name pathowner holds for the parent.
|
|
613
|
+
function pathEntityName(data, mdesc, parts, pm, pathowner, why) {
|
|
614
|
+
if ('t/p/t/' === pm?.expr) {
|
|
615
|
+
return entityPathMatch_tpte(data, pm, mdesc, pathowner, why);
|
|
616
|
+
}
|
|
617
|
+
else if ('t/p/' === pm?.expr) {
|
|
618
|
+
return entityPathMatch_tpe(data, pm, mdesc, why);
|
|
619
|
+
}
|
|
620
|
+
else if ('p/t/' === pm?.expr) {
|
|
621
|
+
return entityPathMatch_pte(data, pm, mdesc, why);
|
|
622
|
+
}
|
|
623
|
+
else if ('t/' === pm?.expr) {
|
|
624
|
+
return entityPathMatch_te(data, pm, mdesc, why);
|
|
625
|
+
}
|
|
626
|
+
else if ('t/p/p' === pm?.expr) {
|
|
627
|
+
return entityPathMatch_tpp(data, pm, mdesc, why);
|
|
628
|
+
}
|
|
629
|
+
return inferEntityName(mdesc, parts, why);
|
|
630
|
+
}
|
|
631
|
+
// The entity a path's own record names, where the record carries the name the
|
|
632
|
+
// path's last segment gives.
|
|
633
|
+
function markRecordOwner(recordowner, pathStr, parts, ment, entname) {
|
|
634
|
+
const last = parts.filter((part) => !isParam(part)).pop();
|
|
635
|
+
if (null == recordowner[pathStr] && isSchemaRef(ment.ref) &&
|
|
636
|
+
entname === ment.cmp && null != last && entname === (0, utility_2.canonize)(last)) {
|
|
637
|
+
recordowner[pathStr] = entname;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
581
640
|
function RenameParams(spec) {
|
|
582
641
|
const ctx = spec.ctx;
|
|
583
642
|
const data = spec.data;
|
|
@@ -881,10 +940,16 @@ function ResolveTransform(spec) {
|
|
|
881
940
|
// project in Neon's project create beside its branch and roles, and may
|
|
882
941
|
// declare properties of its own beside them.
|
|
883
942
|
const partprops = (0, utility_2.mergedProperties)(resschema);
|
|
884
|
-
|
|
943
|
+
// A list reads records, so an object named for the entity does not win over
|
|
944
|
+
// a list of them beside it, such as the matches beside the competition a
|
|
945
|
+
// page of them repeats. The list is found in the same parts the name is.
|
|
946
|
+
const records = 'list' === opname && null != partprops ? (0, utility_1.envelopeProp)(partprops, opname) : null;
|
|
947
|
+
const holdsRecord = (prop) => (0, utility_1.isEntityWrapperProp)(prop) &&
|
|
948
|
+
(null == records || true === (0, utility_1.propIsList)(prop));
|
|
949
|
+
if (named && holdsRecord(partprops?.[entdesc.origname])) {
|
|
885
950
|
transform.res = '`body.' + entdesc.origname + '`';
|
|
886
951
|
}
|
|
887
|
-
else if (named && (
|
|
952
|
+
else if (named && holdsRecord(partprops?.[entdesc.name])) {
|
|
888
953
|
transform.res = '`body.' + entdesc.name + '`';
|
|
889
954
|
}
|
|
890
955
|
else if (resprops) {
|
|
@@ -904,33 +969,18 @@ function ResolveTransform(spec) {
|
|
|
904
969
|
transform.res = '`body.' + envelope + '`';
|
|
905
970
|
}
|
|
906
971
|
}
|
|
907
|
-
|
|
908
|
-
const
|
|
909
|
-
(
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
(0, struct_1.keysof)(reqprops).every((k) => k === name);
|
|
915
|
-
if (reqschema) {
|
|
916
|
-
if (wraps(entdesc.origname)) {
|
|
917
|
-
transform.req = { [entdesc.origname]: '`reqdata`' };
|
|
918
|
-
}
|
|
919
|
-
else if (wraps(entdesc.name)) {
|
|
920
|
-
transform.req = { [entdesc.name]: '`reqdata`' };
|
|
921
|
-
}
|
|
922
|
-
else {
|
|
923
|
-
// A CLOSED body schema names every property the server will accept, so
|
|
924
|
-
// the body is those properties — not the whole request payload. The
|
|
925
|
-
// payload also carries the op's PATH params (`id` for
|
|
926
|
-
// `PUT /item/{id}`), and a closed shape rejects the entire request over
|
|
927
|
-
// that one extra key: every update came back 400 with `invalid-data`.
|
|
928
|
-
const body = (0, utility_1.closedBodyTransform)(reqschema);
|
|
929
|
-
if (null != body) {
|
|
930
|
-
transform.req = body;
|
|
931
|
-
}
|
|
972
|
+
// An item that is the entity's own component is the record, as above.
|
|
973
|
+
const itemref = resschema?.items?.['x-ref'];
|
|
974
|
+
if (null == transform.res && 'list' === opname &&
|
|
975
|
+
(null == itemref || null == entdesc.cmp || cmpRefName(itemref) !== entdesc.cmp)) {
|
|
976
|
+
const key = (0, utility_1.itemEnvelopeKey)(resschema, [entdesc.origname, entdesc.name]);
|
|
977
|
+
if (null != key) {
|
|
978
|
+
transform.res = (0, utility_1.itemEnvelopeTransform)(key);
|
|
932
979
|
}
|
|
933
980
|
}
|
|
981
|
+
const reqschema = getRequestBodySchema(mdesc.requestBody);
|
|
982
|
+
(0, utility_2.debugpath)(pathStr, methodName, 'TRANSFORM-REQ', (0, struct_1.keysof)(reqschema?.properties));
|
|
983
|
+
transform.req = (0, utility_1.bodyRequestTransform)(reqschema, [entdesc.origname, entdesc.name]);
|
|
934
984
|
if (!(0, struct_1.isempty)(transform) && null != op[opname]) {
|
|
935
985
|
op[opname].transform = transform;
|
|
936
986
|
}
|
|
@@ -973,7 +1023,7 @@ function BuildEntity(spec) {
|
|
|
973
1023
|
}
|
|
974
1024
|
entityMap[entdesc.name] = guideEntity;
|
|
975
1025
|
}
|
|
976
|
-
function entityPathMatch_tpte(data, pm, mdesc, why) {
|
|
1026
|
+
function entityPathMatch_tpte(data, pm, mdesc, pathowner, why) {
|
|
977
1027
|
const ment = mdesc.MethodEntity;
|
|
978
1028
|
const pathNameIndex = PATH_NAME_INDEX['t/p/t/'];
|
|
979
1029
|
why.push('path=t/p/t/');
|
|
@@ -981,7 +1031,7 @@ function entityPathMatch_tpte(data, pm, mdesc, why) {
|
|
|
981
1031
|
let entname = (0, utility_2.canonize)(origPathName);
|
|
982
1032
|
let ecm = undefined;
|
|
983
1033
|
if (null != ment.cmp) {
|
|
984
|
-
const parent = verbOnParent(data, pm, mdesc);
|
|
1034
|
+
const parent = verbOnParent(data, pm, mdesc, pathowner);
|
|
985
1035
|
if (null != parent) {
|
|
986
1036
|
entname = parent;
|
|
987
1037
|
ment.verb_on_parent = (0, struct_1.getelem)(pm, -1);
|
|
@@ -1023,7 +1073,7 @@ function endsWithCmp(data, pm) {
|
|
|
1023
1073
|
const last = (0, utility_2.canonize)((0, struct_1.getelem)(pm, -1));
|
|
1024
1074
|
return isOrigCmp(data, last);
|
|
1025
1075
|
}
|
|
1026
|
-
function verbOnParent(data, pm, mdesc) {
|
|
1076
|
+
function verbOnParent(data, pm, mdesc, pathowner) {
|
|
1027
1077
|
const method = mdesc.method;
|
|
1028
1078
|
if (READ_METHODS.includes(method)) {
|
|
1029
1079
|
return null;
|
|
@@ -1066,7 +1116,7 @@ function verbOnParent(data, pm, mdesc) {
|
|
|
1066
1116
|
// known. The parent is the entity a READ of the item returns: a PUT on
|
|
1067
1117
|
// the item answering with a one-off acknowledgement is named after that
|
|
1068
1118
|
// and must not claim the verb. Fall back to any owner, then the literal.
|
|
1069
|
-
const owners =
|
|
1119
|
+
const owners = pathowner[itemPath] ?? {};
|
|
1070
1120
|
const parent = owners.GET ?? owners.QUERY ??
|
|
1071
1121
|
Object.values(owners).sort()[0];
|
|
1072
1122
|
if (null != parent) {
|
|
@@ -1074,15 +1124,11 @@ function verbOnParent(data, pm, mdesc) {
|
|
|
1074
1124
|
}
|
|
1075
1125
|
return (0, utility_2.canonize)((0, struct_1.getelem)(pm, -3));
|
|
1076
1126
|
}
|
|
1077
|
-
// The
|
|
1078
|
-
//
|
|
1079
|
-
|
|
1080
|
-
// would join: the collection's record then names the item too, as GitHub's
|
|
1081
|
-
// repository invitations do beside its repositories.
|
|
1082
|
-
function itemOfCollection(data, mdesc, parts) {
|
|
1127
|
+
// The collection of an item route whose method its tag alone names, when the
|
|
1128
|
+
// route answers nothing.
|
|
1129
|
+
function tagItemCollection(data, mdesc, parts) {
|
|
1083
1130
|
const ment = mdesc.MethodEntity;
|
|
1084
|
-
if ('tag' !== ment.ref || null != ment.rescmp
|
|
1085
|
-
true !== data.work.recordResources[ment.cmp]) {
|
|
1131
|
+
if (null == ment || 'tag' !== ment.ref || null != ment.rescmp) {
|
|
1086
1132
|
return null;
|
|
1087
1133
|
}
|
|
1088
1134
|
const lits = parts.slice(0, parts.findIndex(isParam));
|
|
@@ -1092,12 +1138,85 @@ function itemOfCollection(data, mdesc, parts) {
|
|
|
1092
1138
|
const answers = Object.entries(data.def?.paths?.[mdesc.path] ?? {})
|
|
1093
1139
|
.some(([method, mdef]) => null != METHOD_CONSIDER_ORDER[method.toUpperCase()] &&
|
|
1094
1140
|
null != getResponseSchema(successResponse(mdef?.responses)));
|
|
1095
|
-
|
|
1141
|
+
return answers ? null : '/' + lits.join('/');
|
|
1142
|
+
}
|
|
1143
|
+
// The collection that names a tag-named item route, given the record owners
|
|
1144
|
+
// known so far: by its record, where the tag names another resource with one
|
|
1145
|
+
// (GitHub's invitations), or by its segment, where the routes the tag gathers
|
|
1146
|
+
// from several collections would share a selector (Apicurio's well-known
|
|
1147
|
+
// routes). Null where the route keeps the name its own path gives.
|
|
1148
|
+
function collectionNaming(data, mdesc, parts, recordowner) {
|
|
1149
|
+
const collection = tagItemCollection(data, mdesc, parts);
|
|
1150
|
+
if (null == collection) {
|
|
1096
1151
|
return null;
|
|
1097
1152
|
}
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1153
|
+
const work = data.work;
|
|
1154
|
+
const cmp = mdesc.MethodEntity.cmp;
|
|
1155
|
+
if (true === work.recordResources[cmp]) {
|
|
1156
|
+
const record = recordowner[collection] ?? recordowner[collection + '/'];
|
|
1157
|
+
return null == record ? null : { collection, record };
|
|
1158
|
+
}
|
|
1159
|
+
return tagCollides(data.def, work.tagItems[cmp] ?? {}) ? { collection } : null;
|
|
1160
|
+
}
|
|
1161
|
+
// The entity of an item route its collection names: the collection's record,
|
|
1162
|
+
// or its segment. A route outside the collection that has the segment puts the
|
|
1163
|
+
// tag before it, and one that has that name too a number from 2 after it, up
|
|
1164
|
+
// to the first number that leaves the stored form as it was.
|
|
1165
|
+
function itemOfCollection(data, mdesc, parts) {
|
|
1166
|
+
const naming = collectionNaming(data, mdesc, parts, data.work.recordowner);
|
|
1167
|
+
if (null == naming) {
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
if (null != naming.record) {
|
|
1171
|
+
return { name: naming.record, why: 'collection-record' };
|
|
1172
|
+
}
|
|
1173
|
+
const collection = naming.collection;
|
|
1174
|
+
const segment = (0, utility_2.canonize)(collection.substring(collection.lastIndexOf('/') + 1));
|
|
1175
|
+
if (!segmentHeld(data.work, segment, collection)) {
|
|
1176
|
+
return { name: segment, why: 'collection-segment' };
|
|
1177
|
+
}
|
|
1178
|
+
const tagged = mdesc.MethodEntity.cmp + '_' + segment;
|
|
1179
|
+
let name = tagged;
|
|
1180
|
+
for (let i = 2; segmentHeld(data.work, name, collection); i++) {
|
|
1181
|
+
const stored = (0, utility_2.ensureMinEntityName)(name, {});
|
|
1182
|
+
name = tagged + i;
|
|
1183
|
+
if ((0, utility_2.ensureMinEntityName)(name, {}) === stored) {
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return { name, why: 'collection-segment' };
|
|
1188
|
+
}
|
|
1189
|
+
// A route outside the collection has the name: one named already under the
|
|
1190
|
+
// key the name would take now, or one that claims the name, its stored form
|
|
1191
|
+
// or that key. An item route its collection names makes no claim, so it
|
|
1192
|
+
// counts only once named.
|
|
1193
|
+
function segmentHeld(work, name, collection) {
|
|
1194
|
+
const outside = (path) => !(path + '/').startsWith(collection + '/');
|
|
1195
|
+
const key = (0, utility_2.ensureMinEntityName)(name, work.entmap);
|
|
1196
|
+
const stored = (0, utility_2.ensureMinEntityName)(name, {});
|
|
1197
|
+
return [work.entmap[key]?.path, work.claims[name], work.claims[stored], work.claims[key]]
|
|
1198
|
+
.some((paths) => Object.keys(paths ?? {}).some(outside));
|
|
1199
|
+
}
|
|
1200
|
+
// Two of a tag's collections whose item routes take the same parameters, or
|
|
1201
|
+
// that are both read, would share a selector on the tag's entity.
|
|
1202
|
+
function tagCollides(def, items) {
|
|
1203
|
+
const seen = {};
|
|
1204
|
+
let reads = 0;
|
|
1205
|
+
for (const [collection, params] of Object.entries(items)) {
|
|
1206
|
+
for (const key of Object.keys(params)) {
|
|
1207
|
+
if (seen[key]) {
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
seen[key] = true;
|
|
1211
|
+
}
|
|
1212
|
+
if (pathReads(def.paths?.[collection]) || pathReads(def.paths?.[collection + '/'])) {
|
|
1213
|
+
reads++;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
return 1 < reads;
|
|
1217
|
+
}
|
|
1218
|
+
function pathReads(pathdef) {
|
|
1219
|
+
return Object.entries(pathdef ?? {}).some(([method, mdef]) => 'GET' === method.toUpperCase() && null != mdef);
|
|
1101
1220
|
}
|
|
1102
1221
|
function isSchemaRef(ref) {
|
|
1103
1222
|
return null != ref && '' !== ref && 'tag' !== ref;
|
|
@@ -1169,8 +1288,7 @@ function entityPathMatch_tpp(data, pm, mdesc, why) {
|
|
|
1169
1288
|
return entname;
|
|
1170
1289
|
}
|
|
1171
1290
|
function getRequestBodySchema(requestBody) {
|
|
1172
|
-
return requestBody?.
|
|
1173
|
-
requestBody?.schema;
|
|
1291
|
+
return (0, body_1.jsonRequestSchema)({ requestBody }) ?? requestBody?.schema;
|
|
1174
1292
|
}
|
|
1175
1293
|
// The response an operation's result is read from, down to an Accepted
|
|
1176
1294
|
// response when nothing else answers, whose body may be the job it queued.
|
|
@@ -1601,16 +1719,18 @@ function isListResponse(mdesc, pm, pathStr, why) {
|
|
|
1601
1719
|
(0, utility_2.debugpath)(pathStr, mdesc.method, 'IS-LIST', islist, why, schema);
|
|
1602
1720
|
return islist;
|
|
1603
1721
|
}
|
|
1722
|
+
// struct's merge rewrites every list element it walks, not just the first, so
|
|
1723
|
+
// each schema is cloned: the definition shares one object per $ref target.
|
|
1604
1724
|
function resolveSchemaProperties(schema) {
|
|
1605
1725
|
let properties = {};
|
|
1606
1726
|
// This is definitely heuristic!
|
|
1607
1727
|
if (schema.allOf) {
|
|
1608
1728
|
for (let i = schema.allOf.length - 1; -1 < i; --i) {
|
|
1609
|
-
properties = (0, struct_1.merge)([properties, schema.allOf[i].properties || {}]);
|
|
1729
|
+
properties = (0, struct_1.merge)([properties, (0, struct_1.clone)(schema.allOf[i].properties || {})]);
|
|
1610
1730
|
}
|
|
1611
1731
|
}
|
|
1612
1732
|
if (schema.properties) {
|
|
1613
|
-
properties = (0, struct_1.merge)([properties, schema.properties]);
|
|
1733
|
+
properties = (0, struct_1.merge)([properties, (0, struct_1.clone)(schema.properties)]);
|
|
1614
1734
|
}
|
|
1615
1735
|
return properties;
|
|
1616
1736
|
}
|
|
@@ -1830,10 +1950,37 @@ function findPotentialSchemaRefs(pathStr, methodName, responses, envelope, answe
|
|
|
1830
1950
|
(0, utility_2.debugpath)(pathStr, methodName, 'POTENTIAL-SCHEMA-REFS', xrefs);
|
|
1831
1951
|
return xrefs;
|
|
1832
1952
|
}
|
|
1953
|
+
const CMP_REF_RE = /\/(components\/schemas|definitions)\/(.+)$/;
|
|
1833
1954
|
function cmpRefName(xref) {
|
|
1834
|
-
const m = xref.match(
|
|
1955
|
+
const m = xref.match(CMP_REF_RE);
|
|
1835
1956
|
return null == m ? xref : (0, utility_2.canonizeCmpName)(m[2]);
|
|
1836
1957
|
}
|
|
1958
|
+
// An array request body is sent from a field named for the records it lists:
|
|
1959
|
+
// its items' component, or the one their allOf parts name, cleaned as an
|
|
1960
|
+
// entity's is, else the entity itself. A pointer into a component names a
|
|
1961
|
+
// part of it, not a record. A name another route of the operation has is taken.
|
|
1962
|
+
function arrayBodyField(schema, entname, taken = []) {
|
|
1963
|
+
const refs = [...new Set(itemRefs(schema?.items, new Set()))];
|
|
1964
|
+
const cmp = String(1 === refs.length ? refs[0] : '').match(CMP_REF_RE)?.[2];
|
|
1965
|
+
const cleaned = null == cmp || cmp.includes('/') ? '' :
|
|
1966
|
+
(0, utility_2.prefixLeadingDigit)((0, utility_2.cleanComponentName)((0, utility_2.canonizeCmpName)(cmp)));
|
|
1967
|
+
const record = '' === cleaned ? entname : cleaned;
|
|
1968
|
+
let name = (0, utility_2.pluralize)(record);
|
|
1969
|
+
for (let n = 1; taken.includes(name); n++) {
|
|
1970
|
+
name = record + '_list' + (1 < n ? n : '');
|
|
1971
|
+
}
|
|
1972
|
+
return name;
|
|
1973
|
+
}
|
|
1974
|
+
function itemRefs(items, seen) {
|
|
1975
|
+
if (null == items || 'object' !== typeof items || seen.has(items)) {
|
|
1976
|
+
return [];
|
|
1977
|
+
}
|
|
1978
|
+
seen.add(items);
|
|
1979
|
+
if ('string' === typeof items['x-ref']) {
|
|
1980
|
+
return [items['x-ref']];
|
|
1981
|
+
}
|
|
1982
|
+
return (Array.isArray(items.allOf) ? items.allOf : []).flatMap((part) => itemRefs(part, seen));
|
|
1983
|
+
}
|
|
1837
1984
|
function hasMethod(def, pathStr, methodName) {
|
|
1838
1985
|
const pathDef = def?.paths?.[pathStr];
|
|
1839
1986
|
const found = (null != pathDef
|