@voxgig/apidef 8.23.0 → 8.25.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.
Files changed (42) hide show
  1. package/dist/builder/entity/entity.d.ts +2 -1
  2. package/dist/builder/entity/entity.js +14 -11
  3. package/dist/builder/entity/entity.js.map +1 -1
  4. package/dist/guide/guide.js +5 -2
  5. package/dist/guide/guide.js.map +1 -1
  6. package/dist/guide/heuristic01.d.ts +2 -1
  7. package/dist/guide/heuristic01.js +251 -86
  8. package/dist/guide/heuristic01.js.map +1 -1
  9. package/dist/model.d.ts +1 -0
  10. package/dist/transform/args.d.ts +4 -1
  11. package/dist/transform/args.js +42 -13
  12. package/dist/transform/args.js.map +1 -1
  13. package/dist/transform/body.d.ts +21 -2
  14. package/dist/transform/body.js +228 -15
  15. package/dist/transform/body.js.map +1 -1
  16. package/dist/transform/field.d.ts +3 -1
  17. package/dist/transform/field.js +154 -91
  18. package/dist/transform/field.js.map +1 -1
  19. package/dist/transform/operation.js +77 -24
  20. package/dist/transform/operation.js.map +1 -1
  21. package/dist/transform/select.js +10 -4
  22. package/dist/transform/select.js.map +1 -1
  23. package/dist/transform/top.d.ts +2 -1
  24. package/dist/transform/top.js +50 -3
  25. package/dist/transform/top.js.map +1 -1
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/dist/utility.d.ts +10 -1
  28. package/dist/utility.js +145 -13
  29. package/dist/utility.js.map +1 -1
  30. package/model/apidef.aontu +1 -0
  31. package/package.json +1 -1
  32. package/src/builder/entity/entity.ts +17 -15
  33. package/src/guide/guide.ts +5 -3
  34. package/src/guide/heuristic01.ts +316 -94
  35. package/src/model.ts +2 -0
  36. package/src/transform/args.ts +50 -14
  37. package/src/transform/body.ts +280 -16
  38. package/src/transform/field.ts +184 -91
  39. package/src/transform/operation.ts +97 -26
  40. package/src/transform/select.ts +13 -4
  41. package/src/transform/top.ts +59 -3
  42. package/src/utility.ts +177 -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
- return caught.methods || [];
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,41 +560,27 @@ 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
- if ('t/p/t/' === pm?.expr) {
510
- entname = entityPathMatch_tpte(data, pm, mdesc, why_path);
511
- }
512
- else if ('t/p/' === pm?.expr) {
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 collectionEntity = itemOfCollection(data, mdesc, parts);
533
- if (null != collectionEntity) {
534
- why_path.push('collection-record=' + collectionEntity);
535
- entname = collectionEntity;
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
539
577
  // (numeric suffix) — see ensureMinEntityName.
540
578
  const rawEntname = entname;
541
- entname = (0, utility_2.ensureMinEntityName)(entname, work.entmap);
579
+ // A numbered stored form, or an entity's own name a verb reads, is kept,
580
+ // since a cut would drop its number.
581
+ if (true !== item?.stored && null == work.entmap[entname]) {
582
+ entname = (0, utility_2.ensureMinEntityName)(entname, work.entmap);
583
+ }
542
584
  const entdesc = work.entmap[entname] = work.entmap[entname] ?? {
543
585
  name: entname,
544
586
  id: 'N' + ('' + Math.random()).substring(2, 10),
@@ -562,22 +604,43 @@ function ResolveEntityName(spec) {
562
604
  // split across entities by method (a PUT answering with a one-off
563
605
  // acknowledgement is named after it), and the parent of a verb is the
564
606
  // entity a read of the item returns.
565
- work.pathowner = work.pathowner ?? {};
566
607
  work.pathowner[pathStr] = work.pathowner[pathStr] ?? {};
567
608
  work.pathowner[pathStr][methodName] = entname;
568
- // The entity a path's own record names, where the record carries the name
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
- }
609
+ markRecordOwner(work.recordowner, pathStr, parts, ment, entname);
576
610
  // Same guard, same reason: the formatting is the cost, not the call.
577
611
  if ((0, utility_2.debugpathOn)()) {
578
612
  (0, utility_2.debugpath)(pathStr, methodName, 'RESOLVE-ENTITY-NAME', (0, utility_2.formatJSONIC)({ entdesc, ment }, { hsepd: 0, $: true, color: true }));
579
613
  }
580
614
  }
615
+ // The name a method's path shape and component give it, or null where neither
616
+ // does. A verb on a parent takes the name pathowner holds for the parent.
617
+ function pathEntityName(data, mdesc, parts, pm, pathowner, why) {
618
+ if ('t/p/t/' === pm?.expr) {
619
+ return entityPathMatch_tpte(data, pm, mdesc, pathowner, why);
620
+ }
621
+ else if ('t/p/' === pm?.expr) {
622
+ return entityPathMatch_tpe(data, pm, mdesc, why);
623
+ }
624
+ else if ('p/t/' === pm?.expr) {
625
+ return entityPathMatch_pte(data, pm, mdesc, why);
626
+ }
627
+ else if ('t/' === pm?.expr) {
628
+ return entityPathMatch_te(data, pm, mdesc, why);
629
+ }
630
+ else if ('t/p/p' === pm?.expr) {
631
+ return entityPathMatch_tpp(data, pm, mdesc, why);
632
+ }
633
+ return inferEntityName(mdesc, parts, why);
634
+ }
635
+ // The entity a path's own record names, where the record carries the name the
636
+ // path's last segment gives.
637
+ function markRecordOwner(recordowner, pathStr, parts, ment, entname) {
638
+ const last = parts.filter((part) => !isParam(part)).pop();
639
+ if (null == recordowner[pathStr] && isSchemaRef(ment.ref) &&
640
+ entname === ment.cmp && null != last && entname === (0, utility_2.canonize)(last)) {
641
+ recordowner[pathStr] = entname;
642
+ }
643
+ }
581
644
  function RenameParams(spec) {
582
645
  const ctx = spec.ctx;
583
646
  const data = spec.data;
@@ -881,10 +944,16 @@ function ResolveTransform(spec) {
881
944
  // project in Neon's project create beside its branch and roles, and may
882
945
  // declare properties of its own beside them.
883
946
  const partprops = (0, utility_2.mergedProperties)(resschema);
884
- if (named && (0, utility_1.isEntityWrapperProp)(partprops?.[entdesc.origname])) {
947
+ // A list reads records, so an object named for the entity does not win over
948
+ // a list of them beside it, such as the matches beside the competition a
949
+ // page of them repeats. The list is found in the same parts the name is.
950
+ const records = 'list' === opname && null != partprops ? (0, utility_1.envelopeProp)(partprops, opname) : null;
951
+ const holdsRecord = (prop) => (0, utility_1.isEntityWrapperProp)(prop) &&
952
+ (null == records || true === (0, utility_1.propIsList)(prop));
953
+ if (named && holdsRecord(partprops?.[entdesc.origname])) {
885
954
  transform.res = '`body.' + entdesc.origname + '`';
886
955
  }
887
- else if (named && (0, utility_1.isEntityWrapperProp)(partprops?.[entdesc.name])) {
956
+ else if (named && holdsRecord(partprops?.[entdesc.name])) {
888
957
  transform.res = '`body.' + entdesc.name + '`';
889
958
  }
890
959
  else if (resprops) {
@@ -904,33 +973,18 @@ function ResolveTransform(spec) {
904
973
  transform.res = '`body.' + envelope + '`';
905
974
  }
906
975
  }
907
- const reqschema = getRequestBodySchema(mdesc.requestBody);
908
- const reqprops = reqschema?.properties;
909
- (0, utility_2.debugpath)(pathStr, methodName, 'TRANSFORM-REQ', (0, struct_1.keysof)(reqprops));
910
- // A body wraps the record under the entity's name only when that is all it
911
- // holds, and it is structured. Otherwise the name is one field of the record,
912
- // such as the container in SaladCloud's container group create.
913
- const wraps = (name) => (0, utility_1.isEntityWrapperProp)(reqprops?.[name]) &&
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
- }
976
+ // An item that is the entity's own component is the record, as above.
977
+ const itemref = resschema?.items?.['x-ref'];
978
+ if (null == transform.res && 'list' === opname &&
979
+ (null == itemref || null == entdesc.cmp || cmpRefName(itemref) !== entdesc.cmp)) {
980
+ const key = (0, utility_1.itemEnvelopeKey)(resschema, [entdesc.origname, entdesc.name]);
981
+ if (null != key) {
982
+ transform.res = (0, utility_1.itemEnvelopeTransform)(key);
932
983
  }
933
984
  }
985
+ const reqschema = getRequestBodySchema(mdesc.requestBody);
986
+ (0, utility_2.debugpath)(pathStr, methodName, 'TRANSFORM-REQ', (0, struct_1.keysof)(reqschema?.properties));
987
+ transform.req = (0, utility_1.bodyRequestTransform)(reqschema, [entdesc.origname, entdesc.name]);
934
988
  if (!(0, struct_1.isempty)(transform) && null != op[opname]) {
935
989
  op[opname].transform = transform;
936
990
  }
@@ -973,7 +1027,7 @@ function BuildEntity(spec) {
973
1027
  }
974
1028
  entityMap[entdesc.name] = guideEntity;
975
1029
  }
976
- function entityPathMatch_tpte(data, pm, mdesc, why) {
1030
+ function entityPathMatch_tpte(data, pm, mdesc, pathowner, why) {
977
1031
  const ment = mdesc.MethodEntity;
978
1032
  const pathNameIndex = PATH_NAME_INDEX['t/p/t/'];
979
1033
  why.push('path=t/p/t/');
@@ -981,7 +1035,7 @@ function entityPathMatch_tpte(data, pm, mdesc, why) {
981
1035
  let entname = (0, utility_2.canonize)(origPathName);
982
1036
  let ecm = undefined;
983
1037
  if (null != ment.cmp) {
984
- const parent = verbOnParent(data, pm, mdesc);
1038
+ const parent = verbOnParent(data, pm, mdesc, pathowner);
985
1039
  if (null != parent) {
986
1040
  entname = parent;
987
1041
  ment.verb_on_parent = (0, struct_1.getelem)(pm, -1);
@@ -1023,7 +1077,7 @@ function endsWithCmp(data, pm) {
1023
1077
  const last = (0, utility_2.canonize)((0, struct_1.getelem)(pm, -1));
1024
1078
  return isOrigCmp(data, last);
1025
1079
  }
1026
- function verbOnParent(data, pm, mdesc) {
1080
+ function verbOnParent(data, pm, mdesc, pathowner) {
1027
1081
  const method = mdesc.method;
1028
1082
  if (READ_METHODS.includes(method)) {
1029
1083
  return null;
@@ -1066,7 +1120,7 @@ function verbOnParent(data, pm, mdesc) {
1066
1120
  // known. The parent is the entity a READ of the item returns: a PUT on
1067
1121
  // the item answering with a one-off acknowledgement is named after that
1068
1122
  // and must not claim the verb. Fall back to any owner, then the literal.
1069
- const owners = data.work.pathowner?.[itemPath] ?? {};
1123
+ const owners = pathowner[itemPath] ?? {};
1070
1124
  const parent = owners.GET ?? owners.QUERY ??
1071
1125
  Object.values(owners).sort()[0];
1072
1126
  if (null != parent) {
@@ -1074,15 +1128,11 @@ function verbOnParent(data, pm, mdesc) {
1074
1128
  }
1075
1129
  return (0, utility_2.canonize)((0, struct_1.getelem)(pm, -3));
1076
1130
  }
1077
- // The entity of an item route's collection, for a method on the item route
1078
- // named by its tag alone, when the route answers nothing and the tag names
1079
- // another resource with a record of its own, which the item's operations
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) {
1131
+ // The collection of an item route whose method its tag alone names, when the
1132
+ // route answers nothing.
1133
+ function tagItemCollection(data, mdesc, parts) {
1083
1134
  const ment = mdesc.MethodEntity;
1084
- if ('tag' !== ment.ref || null != ment.rescmp ||
1085
- true !== data.work.recordResources[ment.cmp]) {
1135
+ if (null == ment || 'tag' !== ment.ref || null != ment.rescmp) {
1086
1136
  return null;
1087
1137
  }
1088
1138
  const lits = parts.slice(0, parts.findIndex(isParam));
@@ -1092,12 +1142,99 @@ function itemOfCollection(data, mdesc, parts) {
1092
1142
  const answers = Object.entries(data.def?.paths?.[mdesc.path] ?? {})
1093
1143
  .some(([method, mdef]) => null != METHOD_CONSIDER_ORDER[method.toUpperCase()] &&
1094
1144
  null != getResponseSchema(successResponse(mdef?.responses)));
1095
- if (answers) {
1145
+ return answers ? null : '/' + lits.join('/');
1146
+ }
1147
+ // The collection that names a tag-named item route, given the record owners
1148
+ // known so far: by its record, where the tag names another resource with one
1149
+ // (GitHub's invitations), or by its segment, where the routes the tag gathers
1150
+ // from several collections would share a selector (Apicurio's well-known
1151
+ // routes). Null where the route keeps the name its own path gives.
1152
+ function collectionNaming(data, mdesc, parts, recordowner) {
1153
+ const collection = tagItemCollection(data, mdesc, parts);
1154
+ if (null == collection) {
1096
1155
  return null;
1097
1156
  }
1098
- const collection = '/' + lits.join('/');
1099
- return data.work.recordowner?.[collection] ??
1100
- data.work.recordowner?.[collection + '/'] ?? null;
1157
+ const work = data.work;
1158
+ const cmp = mdesc.MethodEntity.cmp;
1159
+ if (true === work.recordResources[cmp]) {
1160
+ const record = recordowner[collection] ?? recordowner[collection + '/'];
1161
+ return null == record ? null : { collection, record };
1162
+ }
1163
+ return tagCollides(data.def, work.tagItems[cmp] ?? {}) ? { collection } : null;
1164
+ }
1165
+ // The entity of an item route its collection names: the collection's record,
1166
+ // or its segment. A route outside the collection that has the segment puts the
1167
+ // tag before it, and one that has that name too a number from 2 after the
1168
+ // stored form, which a cut would otherwise drop.
1169
+ function itemOfCollection(data, mdesc, parts) {
1170
+ const naming = collectionNaming(data, mdesc, parts, data.work.recordowner);
1171
+ if (null == naming) {
1172
+ return null;
1173
+ }
1174
+ if (null != naming.record) {
1175
+ return { name: naming.record, why: 'collection-record' };
1176
+ }
1177
+ const work = data.work;
1178
+ const collection = naming.collection;
1179
+ const segment = (0, utility_2.canonize)(collection.substring(collection.lastIndexOf('/') + 1));
1180
+ const tagged = mdesc.MethodEntity.cmp + '_' + segment;
1181
+ for (const name of [segment, tagged]) {
1182
+ if (!segmentHeld(work, name, collection)) {
1183
+ return { name, why: 'collection-segment' };
1184
+ }
1185
+ }
1186
+ const stored = (0, utility_2.ensureMinEntityName)(tagged, {});
1187
+ let i = 2;
1188
+ while (keyHeld(work, [stored + i], collection)) {
1189
+ i++;
1190
+ }
1191
+ return { name: stored + i, why: 'collection-segment', stored: true };
1192
+ }
1193
+ // A route outside the collection has the name: one named already under its
1194
+ // stored form or the key it would take now, or one that claims the name, its
1195
+ // stored form or that key.
1196
+ function segmentHeld(work, name, collection) {
1197
+ return keyHeld(work, [name, (0, utility_2.ensureMinEntityName)(name, {}),
1198
+ (0, utility_2.ensureMinEntityName)(name, work.entmap)], collection);
1199
+ }
1200
+ // A route outside the collection is named under one of the keys or claims one.
1201
+ // An item route its collection names makes no claim, so it counts only once
1202
+ // named.
1203
+ function keyHeld(work, keys, collection) {
1204
+ return keys.some((key) => [work.entmap[key]?.path, work.claims[key]]
1205
+ .some((paths) => Object.keys(paths ?? {}).some((path) => outsideCollection(path, collection))));
1206
+ }
1207
+ // A route under the collection is its own when it has no parameter or its
1208
+ // first parameter follows the collection: one under a collection nested in it
1209
+ // is outside.
1210
+ function outsideCollection(path, collection) {
1211
+ if (!(path + '/').startsWith(collection + '/')) {
1212
+ return true;
1213
+ }
1214
+ const parts = path.split('/').filter((part) => '' !== part);
1215
+ const first = parts.findIndex(isParam);
1216
+ return -1 < first && collection !== '/' + parts.slice(0, first).join('/');
1217
+ }
1218
+ // Two of a tag's collections whose item routes take the same parameters, or
1219
+ // that are both read, would share a selector on the tag's entity.
1220
+ function tagCollides(def, items) {
1221
+ const seen = {};
1222
+ let reads = 0;
1223
+ for (const [collection, params] of Object.entries(items)) {
1224
+ for (const key of Object.keys(params)) {
1225
+ if (seen[key]) {
1226
+ return true;
1227
+ }
1228
+ seen[key] = true;
1229
+ }
1230
+ if (pathReads(def.paths?.[collection]) || pathReads(def.paths?.[collection + '/'])) {
1231
+ reads++;
1232
+ }
1233
+ }
1234
+ return 1 < reads;
1235
+ }
1236
+ function pathReads(pathdef) {
1237
+ return Object.entries(pathdef ?? {}).some(([method, mdef]) => 'GET' === method.toUpperCase() && null != mdef);
1101
1238
  }
1102
1239
  function isSchemaRef(ref) {
1103
1240
  return null != ref && '' !== ref && 'tag' !== ref;
@@ -1169,8 +1306,7 @@ function entityPathMatch_tpp(data, pm, mdesc, why) {
1169
1306
  return entname;
1170
1307
  }
1171
1308
  function getRequestBodySchema(requestBody) {
1172
- return requestBody?.content?.['application/json']?.schema ??
1173
- requestBody?.schema;
1309
+ return (0, body_1.jsonRequestSchema)({ requestBody }) ?? requestBody?.schema;
1174
1310
  }
1175
1311
  // The response an operation's result is read from, down to an Accepted
1176
1312
  // response when nothing else answers, whose body may be the job it queued.
@@ -1601,16 +1737,18 @@ function isListResponse(mdesc, pm, pathStr, why) {
1601
1737
  (0, utility_2.debugpath)(pathStr, mdesc.method, 'IS-LIST', islist, why, schema);
1602
1738
  return islist;
1603
1739
  }
1740
+ // struct's merge rewrites every list element it walks, not just the first, so
1741
+ // each schema is cloned: the definition shares one object per $ref target.
1604
1742
  function resolveSchemaProperties(schema) {
1605
1743
  let properties = {};
1606
1744
  // This is definitely heuristic!
1607
1745
  if (schema.allOf) {
1608
1746
  for (let i = schema.allOf.length - 1; -1 < i; --i) {
1609
- properties = (0, struct_1.merge)([properties, schema.allOf[i].properties || {}]);
1747
+ properties = (0, struct_1.merge)([properties, (0, struct_1.clone)(schema.allOf[i].properties || {})]);
1610
1748
  }
1611
1749
  }
1612
1750
  if (schema.properties) {
1613
- properties = (0, struct_1.merge)([properties, schema.properties]);
1751
+ properties = (0, struct_1.merge)([properties, (0, struct_1.clone)(schema.properties)]);
1614
1752
  }
1615
1753
  return properties;
1616
1754
  }
@@ -1830,10 +1968,37 @@ function findPotentialSchemaRefs(pathStr, methodName, responses, envelope, answe
1830
1968
  (0, utility_2.debugpath)(pathStr, methodName, 'POTENTIAL-SCHEMA-REFS', xrefs);
1831
1969
  return xrefs;
1832
1970
  }
1971
+ const CMP_REF_RE = /\/(components\/schemas|definitions)\/(.+)$/;
1833
1972
  function cmpRefName(xref) {
1834
- const m = xref.match(/\/(components\/schemas|definitions)\/(.+)$/);
1973
+ const m = xref.match(CMP_REF_RE);
1835
1974
  return null == m ? xref : (0, utility_2.canonizeCmpName)(m[2]);
1836
1975
  }
1976
+ // An array request body is sent from a field named for the records it lists:
1977
+ // its items' component, or the one their allOf parts name, cleaned as an
1978
+ // entity's is, else the entity itself. A pointer into a component names a
1979
+ // part of it, not a record. A name another route of the operation has is taken.
1980
+ function arrayBodyField(schema, entname, taken = []) {
1981
+ const refs = [...new Set(itemRefs(schema?.items, new Set()))];
1982
+ const cmp = String(1 === refs.length ? refs[0] : '').match(CMP_REF_RE)?.[2];
1983
+ const cleaned = null == cmp || cmp.includes('/') ? '' :
1984
+ (0, utility_2.prefixLeadingDigit)((0, utility_2.cleanComponentName)((0, utility_2.canonizeCmpName)(cmp)));
1985
+ const record = '' === cleaned ? entname : cleaned;
1986
+ let name = (0, utility_2.pluralize)(record);
1987
+ for (let n = 1; taken.includes(name); n++) {
1988
+ name = record + '_list' + (1 < n ? n : '');
1989
+ }
1990
+ return name;
1991
+ }
1992
+ function itemRefs(items, seen) {
1993
+ if (null == items || 'object' !== typeof items || seen.has(items)) {
1994
+ return [];
1995
+ }
1996
+ seen.add(items);
1997
+ if ('string' === typeof items['x-ref']) {
1998
+ return [items['x-ref']];
1999
+ }
2000
+ return (Array.isArray(items.allOf) ? items.allOf : []).flatMap((part) => itemRefs(part, seen));
2001
+ }
1837
2002
  function hasMethod(def, pathStr, methodName) {
1838
2003
  const pathDef = def?.paths?.[pathStr];
1839
2004
  const found = (null != pathDef