@voxgig/apidef 8.32.3 → 8.33.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/desc.d.ts +6 -0
- package/dist/guide/guide.js +1 -1
- package/dist/guide/guide.js.map +1 -1
- package/dist/guide/heuristic01.d.ts +164 -1
- package/dist/guide/heuristic01.js +1221 -102
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/transform/entity.d.ts +3 -1
- package/dist/transform/entity.js +145 -2
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.js +24 -16
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/operation.js +4 -4
- package/dist/transform/operation.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utility.d.ts +17 -3
- package/dist/utility.js +278 -27
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/src/desc.ts +6 -0
- package/src/guide/guide.ts +1 -1
- package/src/guide/heuristic01.ts +1467 -113
- package/src/transform/entity.ts +163 -3
- package/src/transform/field.ts +29 -17
- package/src/transform/operation.ts +4 -4
- package/src/types.ts +1 -1
- package/src/utility.ts +320 -28
package/src/utility.ts
CHANGED
|
@@ -166,11 +166,15 @@ const IRREGULARS: Record<string, string> = Object.assign(Object.create(null), {
|
|
|
166
166
|
'avalanches': 'avalanche',
|
|
167
167
|
'axes': 'axis',
|
|
168
168
|
'bases': 'base',
|
|
169
|
+
'brownies': 'brownie',
|
|
169
170
|
'caches': 'cache',
|
|
171
|
+
'calories': 'calorie',
|
|
170
172
|
'canoes': 'canoe',
|
|
171
173
|
'cases': 'case',
|
|
172
174
|
'children': 'child',
|
|
173
175
|
'cliches': 'cliche',
|
|
176
|
+
'climaxes': 'climax',
|
|
177
|
+
'cookies': 'cookie',
|
|
174
178
|
'courses': 'course',
|
|
175
179
|
'creches': 'creche',
|
|
176
180
|
'crises': 'crisis',
|
|
@@ -182,17 +186,21 @@ const IRREGULARS: Record<string, string> = Object.assign(Object.create(null), {
|
|
|
182
186
|
'douches': 'douche',
|
|
183
187
|
'enterprises': 'enterprise',
|
|
184
188
|
'exercises': 'exercise',
|
|
189
|
+
'faxes': 'fax',
|
|
185
190
|
'feet': 'foot',
|
|
186
191
|
'fish': 'fish',
|
|
187
192
|
'franchises': 'franchise',
|
|
193
|
+
'freebies': 'freebie',
|
|
188
194
|
'furnaces': 'furnace',
|
|
189
195
|
'geese': 'goose',
|
|
196
|
+
'goalies': 'goalie',
|
|
190
197
|
'headaches': 'headache',
|
|
198
|
+
'hoodies': 'hoodie',
|
|
191
199
|
'horses': 'horse',
|
|
192
200
|
'hoses': 'hose',
|
|
193
201
|
'houses': 'house',
|
|
194
202
|
'indices': 'index',
|
|
195
|
-
'
|
|
203
|
+
'lenses': 'lens',
|
|
196
204
|
'licenses': 'license',
|
|
197
205
|
'matrices': 'matrix',
|
|
198
206
|
'men': 'man',
|
|
@@ -201,6 +209,7 @@ const IRREGULARS: Record<string, string> = Object.assign(Object.create(null), {
|
|
|
201
209
|
'moustaches': 'moustache',
|
|
202
210
|
'movies': 'movie',
|
|
203
211
|
'mustaches': 'mustache',
|
|
212
|
+
'newbies': 'newbie',
|
|
204
213
|
'niches': 'niche',
|
|
205
214
|
'noses': 'nose',
|
|
206
215
|
'notices': 'notice',
|
|
@@ -212,6 +221,7 @@ const IRREGULARS: Record<string, string> = Object.assign(Object.create(null), {
|
|
|
212
221
|
'pauses': 'pause',
|
|
213
222
|
'phases': 'phase',
|
|
214
223
|
'phrases': 'phrase',
|
|
224
|
+
'pickaxes': 'pickaxe',
|
|
215
225
|
'practices': 'practice',
|
|
216
226
|
'premises': 'premise',
|
|
217
227
|
'promises': 'promise',
|
|
@@ -220,20 +230,27 @@ const IRREGULARS: Record<string, string> = Object.assign(Object.create(null), {
|
|
|
220
230
|
'purses': 'purse',
|
|
221
231
|
'quizzes': 'quiz',
|
|
222
232
|
'releases': 'release',
|
|
233
|
+
'rookies': 'rookie',
|
|
223
234
|
'roses': 'rose',
|
|
224
235
|
'people': 'person',
|
|
225
236
|
'phenomena': 'phenomenon',
|
|
237
|
+
'selfies': 'selfie',
|
|
226
238
|
'series': 'series',
|
|
227
239
|
'sheep': 'sheep',
|
|
228
240
|
'shoes': 'shoe',
|
|
241
|
+
'smoothies': 'smoothie',
|
|
229
242
|
'sources': 'source',
|
|
230
243
|
'species': 'species',
|
|
244
|
+
'syntaxes': 'syntax',
|
|
245
|
+
'taxes': 'tax',
|
|
246
|
+
'taxis': 'taxi',
|
|
231
247
|
'teeth': 'tooth',
|
|
232
248
|
'theses': 'thesis',
|
|
233
249
|
'verses': 'verse',
|
|
234
250
|
'vertices': 'vertex',
|
|
235
251
|
'women': 'woman',
|
|
236
252
|
'yes': 'yes',
|
|
253
|
+
'zombies': 'zombie',
|
|
237
254
|
})
|
|
238
255
|
|
|
239
256
|
|
|
@@ -252,6 +269,9 @@ const F_PLURAL_STEMS = [
|
|
|
252
269
|
// today, but the sort makes any future entry safe by construction.
|
|
253
270
|
const IRREGULAR_KEYS = Object.keys(IRREGULARS).sort((a, b) => b.length - a.length)
|
|
254
271
|
|
|
272
|
+
// Singular nouns that end in s, kept whole, as every -sis noun is (analysis).
|
|
273
|
+
const S_SINGULARS = ['alias', 'atlas', 'axis', 'bias', 'canvas', 'lens', 'news']
|
|
274
|
+
|
|
255
275
|
// Nouns in -o whose plural takes -es; the rest take -s (photos).
|
|
256
276
|
const OES_NOUNS = ['echo', 'embargo', 'hero', 'potato', 'tomato', 'torpedo', 'veto']
|
|
257
277
|
|
|
@@ -333,6 +353,10 @@ function depluralize(word: string): string {
|
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
355
|
|
|
356
|
+
if (lower.endsWith('sis') || S_SINGULARS.some((ending) => lower.endsWith(ending))) {
|
|
357
|
+
return word
|
|
358
|
+
}
|
|
359
|
+
|
|
336
360
|
// Rules for regular plurals (applied in order). The -ies and -ves
|
|
337
361
|
// rules add a letter, so they need to match the case of the dropped
|
|
338
362
|
// suffix; all other rules just slice and inherit the caller's case.
|
|
@@ -387,9 +411,11 @@ function depluralize(word: string): string {
|
|
|
387
411
|
return word.slice(0, -2)
|
|
388
412
|
}
|
|
389
413
|
|
|
414
|
+
// A trailing s after a digit is part of a numeronym (k8s), not a plural.
|
|
390
415
|
if (lower.endsWith('s') &&
|
|
391
416
|
!lower.endsWith('ss') &&
|
|
392
417
|
!lower.endsWith('us') &&
|
|
418
|
+
!/[0-9]s$/.test(lower) &&
|
|
393
419
|
word.length > 3
|
|
394
420
|
) {
|
|
395
421
|
return word.slice(0, -1)
|
|
@@ -650,7 +676,7 @@ function pathMatch(path: string | string[], expr: string):
|
|
|
650
676
|
return null
|
|
651
677
|
}
|
|
652
678
|
|
|
653
|
-
const parts =
|
|
679
|
+
const parts = Array.isArray(path) ? path.filter(p => '' !== p) : guideParts(path)
|
|
654
680
|
const res: any = []
|
|
655
681
|
res.index = -1
|
|
656
682
|
res.expr = expr
|
|
@@ -731,8 +757,40 @@ function pathMatch(path: string | string[], expr: string):
|
|
|
731
757
|
}
|
|
732
758
|
|
|
733
759
|
|
|
760
|
+
// A placeholder with any dot or extension it carries: `.{ext}`, `{api}.json`.
|
|
734
761
|
function isParam(partStr: string) {
|
|
735
|
-
|
|
762
|
+
if (null == partStr) {
|
|
763
|
+
return false
|
|
764
|
+
}
|
|
765
|
+
const part = partStr.replace(/^\./, '').replace(/\}\.[A-Za-z0-9]+$/, '}')
|
|
766
|
+
return '{' === part[0] && '}' === part[part.length - 1]
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
// A trailing word that names a module rather than a resource.
|
|
771
|
+
const MODULE_WORDS = ['api', 'controller', 'service', 'resource', 'endpoint']
|
|
772
|
+
|
|
773
|
+
// The entity name a path literal gives: canonized, less a trailing module
|
|
774
|
+
// word when another word remains, as `GadgetsApi` names gadget.
|
|
775
|
+
function literalName(part: string): string {
|
|
776
|
+
const name = canonize(part)
|
|
777
|
+
const at = name.lastIndexOf('_')
|
|
778
|
+
return 0 < at && MODULE_WORDS.includes(name.slice(at + 1)) ?
|
|
779
|
+
depluralize(name.slice(0, at)) : name
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
// The name a placeholder part carries, as `{id}.json` carries id: '' for none.
|
|
784
|
+
function paramOf(part: string): string {
|
|
785
|
+
const m = part.match(/\{([^}]+)\}/)
|
|
786
|
+
return null == m ? '' : m[1]
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
const PARAM_NOUN_SUFFIX_RE = /_(name|id|key|code|slug|number|uuid)$/
|
|
791
|
+
|
|
792
|
+
function paramNoun(name: string): string {
|
|
793
|
+
return canonizeParam(name).replace(PARAM_NOUN_SUFFIX_RE, '')
|
|
736
794
|
}
|
|
737
795
|
|
|
738
796
|
|
|
@@ -1063,6 +1121,9 @@ function nonNullType(type: any): string | undefined {
|
|
|
1063
1121
|
const FILE_EXT_RE =
|
|
1064
1122
|
/\.(php|json|txt|png|jpg|jpeg|gif|svg|xml|html|csv|yml|yaml|md)$/i
|
|
1065
1123
|
|
|
1124
|
+
// Trailing placeholders, dotted or fused: `pets.{format}`, `notes{ext}`.
|
|
1125
|
+
const PLACEHOLDER_EXT_RE = /(\.?\{[^}]*\})+$/
|
|
1126
|
+
|
|
1066
1127
|
function transliterate(s: string): string {
|
|
1067
1128
|
return s.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
|
1068
1129
|
}
|
|
@@ -1079,6 +1140,7 @@ function canonize(s: string) {
|
|
|
1079
1140
|
if (undefined !== cached) return cached
|
|
1080
1141
|
const deacronymed = transliterate(s)
|
|
1081
1142
|
.replace(FILE_EXT_RE, '')
|
|
1143
|
+
.replace(PLACEHOLDER_EXT_RE, '')
|
|
1082
1144
|
.replace(ACRONYM_PLURAL_RE, (_m, run) => run[0] + run.slice(1).toLowerCase() + 's')
|
|
1083
1145
|
const out = depluralize(snakify(deacronymed))
|
|
1084
1146
|
.replace(/[^a-zA-Z_0-9]/g, '')
|
|
@@ -1089,33 +1151,78 @@ function canonize(s: string) {
|
|
|
1089
1151
|
|
|
1090
1152
|
const CANONIZE_FIELD_CACHE = new Map<string, string>()
|
|
1091
1153
|
|
|
1092
|
-
function resplitFromCmp(
|
|
1154
|
+
function resplitFromCmp(
|
|
1155
|
+
entname: string,
|
|
1156
|
+
cmp: string,
|
|
1157
|
+
why: string[],
|
|
1158
|
+
breaks?: Record<string, string>,
|
|
1159
|
+
): string {
|
|
1093
1160
|
if (null == entname || '' === entname || entname.includes('_')) {
|
|
1094
1161
|
return entname
|
|
1095
1162
|
}
|
|
1096
1163
|
|
|
1097
|
-
if (null
|
|
1098
|
-
|
|
1164
|
+
if (null != cmp && '' !== cmp && cmp.includes('_')) {
|
|
1165
|
+
const seg = cmp.split('_')
|
|
1166
|
+
let acc = ''
|
|
1167
|
+
for (let i = 0; i < seg.length && acc.length < entname.length; i++) {
|
|
1168
|
+
acc += seg[i]
|
|
1169
|
+
if (acc === entname) {
|
|
1170
|
+
const split = seg.slice(0, i + 1).join('_')
|
|
1171
|
+
why.push('resplit-from-cmp=' + split)
|
|
1172
|
+
return split
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1099
1175
|
}
|
|
1100
1176
|
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1177
|
+
const split = breaks?.[entname]
|
|
1178
|
+
if (null != split) {
|
|
1179
|
+
why.push('word-break=' + split)
|
|
1180
|
+
return split
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
return entname
|
|
1184
|
+
}
|
|
1103
1185
|
|
|
1104
|
-
for (let i = 0; i < seg.length; i++) {
|
|
1105
|
-
acc += seg[i]
|
|
1106
1186
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1187
|
+
// Multi-word runs from tags, operationIds and component names, keyed by their
|
|
1188
|
+
// letters; where runs disagree, the first in sorted order.
|
|
1189
|
+
function wordBreaks(def: any): Record<string, string> {
|
|
1190
|
+
const names: string[] = []
|
|
1191
|
+
for (const tag of Array.isArray(def?.tags) ? def.tags : []) {
|
|
1192
|
+
names.push(canonize(String(tag?.name ?? '')))
|
|
1193
|
+
}
|
|
1194
|
+
for (const pathdef of Object.values(def?.paths ?? {}) as any[]) {
|
|
1195
|
+
for (const opdef of Object.values(pathdef ?? {}) as any[]) {
|
|
1196
|
+
if (null == opdef || 'object' !== typeof opdef || Array.isArray(opdef)) {
|
|
1197
|
+
continue
|
|
1198
|
+
}
|
|
1199
|
+
for (const tag of Array.isArray(opdef.tags) ? opdef.tags : []) {
|
|
1200
|
+
names.push(canonize(String(tag)))
|
|
1201
|
+
}
|
|
1202
|
+
if ('string' === typeof opdef.operationId) {
|
|
1203
|
+
names.push(canonize(opdef.operationId))
|
|
1204
|
+
}
|
|
1111
1205
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1206
|
+
}
|
|
1207
|
+
for (const name of Object.keys(def?.components?.schemas ?? def?.definitions ?? {})) {
|
|
1208
|
+
names.push(canonizeCmpName(name))
|
|
1209
|
+
}
|
|
1210
|
+
const found: Record<string, string[]> = Object.create(null)
|
|
1211
|
+
for (const name of names) {
|
|
1212
|
+
const words = name.split('_').filter((word) => '' !== word)
|
|
1213
|
+
for (let i = 0; i < words.length; i++) {
|
|
1214
|
+
for (let j = i + 2; j <= words.length; j++) {
|
|
1215
|
+
const run = [...words.slice(i, j - 1), depluralize(words[j - 1])]
|
|
1216
|
+
const key = run.join('')
|
|
1217
|
+
;(found[key] = found[key] ?? []).push(run.join('_'))
|
|
1218
|
+
}
|
|
1115
1219
|
}
|
|
1116
1220
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1221
|
+
const breaks: Record<string, string> = Object.create(null)
|
|
1222
|
+
for (const key of sortedKeys(found)) {
|
|
1223
|
+
breaks[key] = [...found[key]].sort()[0]
|
|
1224
|
+
}
|
|
1225
|
+
return breaks
|
|
1119
1226
|
}
|
|
1120
1227
|
|
|
1121
1228
|
|
|
@@ -1186,9 +1293,11 @@ const FORMAT_EXTENSIONS = new Set([
|
|
|
1186
1293
|
'atom', 'jsonl', 'ndjson', 'geojson',
|
|
1187
1294
|
])
|
|
1188
1295
|
|
|
1189
|
-
// A route segment as the guide reads it: {id}.json
|
|
1190
|
-
// data.{format} are repos and data, and a format alone (json)
|
|
1191
|
-
|
|
1296
|
+
// A route segment as the guide reads it: {id}.json and ${id} are {id},
|
|
1297
|
+
// repos.json and data.{format} are repos and data, and a format alone (json)
|
|
1298
|
+
// names nothing.
|
|
1299
|
+
function guideSegment(seg0: string): string | null {
|
|
1300
|
+
const seg = seg0.replace(/\$\{/g, '{')
|
|
1192
1301
|
const held = seg.match(/^(\{[^}]+\})\.(?:[A-Za-z0-9]+|\{[^}]+\})$/)
|
|
1193
1302
|
if (null != held) return held[1]
|
|
1194
1303
|
const named = seg.match(/^([^{}.]+)\.([A-Za-z0-9]+|\{[^}]+\})$/)
|
|
@@ -1198,9 +1307,12 @@ function guideSegment(seg: string): string | null {
|
|
|
1198
1307
|
return FORMAT_EXTENSIONS.has(seg.toLowerCase()) ? null : seg
|
|
1199
1308
|
}
|
|
1200
1309
|
|
|
1201
|
-
// The guide's parts of a route; a route
|
|
1310
|
+
// The guide's parts of a route, query and fragment cut; a route that is all
|
|
1311
|
+
// fragment, or of formats alone, keeps them.
|
|
1202
1312
|
function guideParts(path: string): string[] {
|
|
1203
|
-
const
|
|
1313
|
+
const split = (route: string) => route.replace(/\?.*$/, '').split('/').filter((p: string) => '' !== p)
|
|
1314
|
+
const cut = split(path.replace(/#.*$/, ''))
|
|
1315
|
+
const parts = 0 === cut.length ? split(path) : cut
|
|
1204
1316
|
const kept = parts.map(guideSegment).filter((p): p is string => null != p)
|
|
1205
1317
|
return 0 === kept.length ? parts : kept
|
|
1206
1318
|
}
|
|
@@ -1387,6 +1499,67 @@ function ensureMinEntityName(
|
|
|
1387
1499
|
}
|
|
1388
1500
|
|
|
1389
1501
|
|
|
1502
|
+
const WRAPPER_WORDS = [
|
|
1503
|
+
'response', 'result', 'ok', 'envelope', 'wrapper', 'payload', 'page', 'paginated',
|
|
1504
|
+
'list', 'collection', 'data', 'body', 'output', 'reply',
|
|
1505
|
+
]
|
|
1506
|
+
|
|
1507
|
+
// The component a wrapper-shaped name wraps, by wrapper words beside it or a
|
|
1508
|
+
// shared wrapper-word prefix naming no component: null for no wrapper, '' for
|
|
1509
|
+
// a wrapper of nothing nameable.
|
|
1510
|
+
function wrapperOf(name: string, known: string[]): string | null {
|
|
1511
|
+
const words = name.split('_').filter((w) => '' !== w)
|
|
1512
|
+
|
|
1513
|
+
// A name of the form noun-for-parent-response, or noun-for-parent once the
|
|
1514
|
+
// response suffix is cleaned away, wraps the noun; `per` reads as `for`.
|
|
1515
|
+
const forAt = words.findIndex((word) => 'for' === word || 'per' === word)
|
|
1516
|
+
if (0 < forAt && forAt < words.length - 1) {
|
|
1517
|
+
const held = depluralize(words.slice(0, forAt).join('_'))
|
|
1518
|
+
if (known.includes(held)) {
|
|
1519
|
+
return held
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
let inner: string | null = null
|
|
1524
|
+
let at = -1
|
|
1525
|
+
for (const k of known) {
|
|
1526
|
+
const kw = k.split('_').filter((w) => '' !== w)
|
|
1527
|
+
if (k === name || 0 === kw.length || (null != inner && kw.length <= inner.split('_').length)) {
|
|
1528
|
+
continue
|
|
1529
|
+
}
|
|
1530
|
+
for (let i = 0; i + kw.length <= words.length; i++) {
|
|
1531
|
+
if (kw.every((w, j) => w === words[i + j])) {
|
|
1532
|
+
inner = k
|
|
1533
|
+
at = i
|
|
1534
|
+
break
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
if (null != inner) {
|
|
1540
|
+
const kw = inner.split('_').length
|
|
1541
|
+
const rest = [...words.slice(0, at), ...words.slice(at + kw)]
|
|
1542
|
+
if (0 < rest.length && rest.every((w) => WRAPPER_WORDS.includes(w))) {
|
|
1543
|
+
return inner
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
const unversioned = known.map((k) => k.replace(/_v\d+$/, ''))
|
|
1548
|
+
for (let n = words.length - 1; 2 <= n; n--) {
|
|
1549
|
+
const prefix = words.slice(0, n).join('_')
|
|
1550
|
+
if (unversioned.includes(prefix)) {
|
|
1551
|
+
break
|
|
1552
|
+
}
|
|
1553
|
+
const members = known.filter((k) => k !== name && k.startsWith(prefix + '_')).length
|
|
1554
|
+
if (2 <= members && words.slice(0, n).some((w) => WRAPPER_WORDS.includes(w))) {
|
|
1555
|
+
return inner ?? ''
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
return null
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
|
|
1390
1563
|
// Unconditional suffixes: framework noise, always stripped.
|
|
1391
1564
|
const CMP_SUFFIXES = ['_rest_controller', '_controller', '_response', '_request']
|
|
1392
1565
|
|
|
@@ -1404,6 +1577,55 @@ const CMP_RESULT_VERBS = [
|
|
|
1404
1577
|
|
|
1405
1578
|
const CMP_PREFIXES = ['get_', 'post_', 'put_', 'delete_', 'patch_']
|
|
1406
1579
|
|
|
1580
|
+
// The leading word run more than half the components, and at least two,
|
|
1581
|
+
// share; none where a path literal, a whole component name or a wrapper word
|
|
1582
|
+
// holds it.
|
|
1583
|
+
function cmpNamespace(def: any): string | null {
|
|
1584
|
+
const schemas = def?.components?.schemas ?? def?.definitions
|
|
1585
|
+
const names = sortedKeys(schemas).map((name) =>
|
|
1586
|
+
canonizeCmpName(name).split('_').filter((word) => '' !== word))
|
|
1587
|
+
const run: string[] = []
|
|
1588
|
+
let shared = 0
|
|
1589
|
+
for (;;) {
|
|
1590
|
+
const at = run.length
|
|
1591
|
+
const tally: Record<string, number> = Object.create(null)
|
|
1592
|
+
for (const words of names) {
|
|
1593
|
+
if (at + 1 < words.length && run.every((word, i) => words[i] === word)) {
|
|
1594
|
+
tally[words[at]] = (tally[words[at]] ?? 0) + 1
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
const next = sortedKeys(tally).find((word) =>
|
|
1598
|
+
0 === at ? names.length < 2 * tally[word] : shared === tally[word])
|
|
1599
|
+
if (null == next) {
|
|
1600
|
+
break
|
|
1601
|
+
}
|
|
1602
|
+
run.push(next)
|
|
1603
|
+
shared = tally[next]
|
|
1604
|
+
}
|
|
1605
|
+
if (shared < 2 || run.some((word) => WRAPPER_WORDS.includes(word)) ||
|
|
1606
|
+
names.some((words) => words.join('_') === run.join('_'))) {
|
|
1607
|
+
return null
|
|
1608
|
+
}
|
|
1609
|
+
const held = run.map((word) => depluralize(word))
|
|
1610
|
+
const literals = Object.keys(def?.paths ?? {}).flatMap((p) => guideParts(p))
|
|
1611
|
+
.filter((part) => !isParam(part))
|
|
1612
|
+
.map((part) => literalName(part).split('_').map((word) => depluralize(word)))
|
|
1613
|
+
const holds = (words: string[]) => words.some((_, i) =>
|
|
1614
|
+
i + held.length <= words.length && held.every((word, j) => words[i + j] === word))
|
|
1615
|
+
return literals.some(holds) ? null : run.join('_')
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
// A name less its namespace, when a name remains.
|
|
1620
|
+
function stripNamespace(name: string, namespace?: string | null): string {
|
|
1621
|
+
if (null == namespace || !name.startsWith(namespace + '_')) {
|
|
1622
|
+
return name
|
|
1623
|
+
}
|
|
1624
|
+
const rest = name.slice(namespace.length + 1)
|
|
1625
|
+
return rest.replace(/_/g, '').length < 3 ? name : rest
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
|
|
1407
1629
|
const OPERATION_VERBS = [
|
|
1408
1630
|
...CMP_RESULT_VERBS, 'post', 'put', 'patch', 'fetch', 'find', 'retrieve', 'read', 'add',
|
|
1409
1631
|
]
|
|
@@ -1484,11 +1706,47 @@ function specSecuredByDefault(def: any): boolean {
|
|
|
1484
1706
|
// The 2xx body schema, OpenAPI 3 (`content`) or Swagger 2 (`schema`).
|
|
1485
1707
|
function successResponseSchema(responses: any): any {
|
|
1486
1708
|
const res = responses?.['200'] ?? responses?.[200] ??
|
|
1487
|
-
responses?.['201'] ?? responses?.[201]
|
|
1709
|
+
responses?.['201'] ?? responses?.[201] ?? rangeResponse(responses)
|
|
1488
1710
|
if (null == res) {
|
|
1489
1711
|
return null
|
|
1490
1712
|
}
|
|
1491
|
-
return res
|
|
1713
|
+
return responseSchema(res) ?? null
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
const JSON_MEDIA_RE = /^[^/;]+\/([^;]*\+)?json\s*(;.*)?$/i
|
|
1718
|
+
|
|
1719
|
+
// The content a response is read from: JSON first, then any other JSON type,
|
|
1720
|
+
// then the any-type range unless it declares binary content.
|
|
1721
|
+
function jsonContent(content: any): any {
|
|
1722
|
+
if (null == content || 'object' !== typeof content) {
|
|
1723
|
+
return undefined
|
|
1724
|
+
}
|
|
1725
|
+
if (null != content['application/json']) {
|
|
1726
|
+
return content['application/json']
|
|
1727
|
+
}
|
|
1728
|
+
const json = sortedKeys(content).find((media) => JSON_MEDIA_RE.test(media))
|
|
1729
|
+
if (null != json) {
|
|
1730
|
+
return content[json]
|
|
1731
|
+
}
|
|
1732
|
+
const schema = content['*/*']?.schema
|
|
1733
|
+
return 'string' === schema?.type && 'binary' === schema?.format ? undefined : content['*/*']
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
// A response's schema, OpenAPI 3 (`content`) or Swagger 2 (`schema`).
|
|
1738
|
+
function responseSchema(response: any): any {
|
|
1739
|
+
return jsonContent(response?.content)?.schema ?? response?.schema
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
// A range code answers for the success codes a definition does not name.
|
|
1744
|
+
function rangeResponse(responses: any): any {
|
|
1745
|
+
if (null == responses || null != responses['200'] || null != responses['201'] ||
|
|
1746
|
+
null != responses['202']) {
|
|
1747
|
+
return undefined
|
|
1748
|
+
}
|
|
1749
|
+
return responses['2XX'] ?? responses['2xx']
|
|
1492
1750
|
}
|
|
1493
1751
|
|
|
1494
1752
|
|
|
@@ -1530,9 +1788,10 @@ function firstFieldMatch(props: string[], names: string[]): string | null {
|
|
|
1530
1788
|
|
|
1531
1789
|
function cleanComponentName(
|
|
1532
1790
|
name: string,
|
|
1533
|
-
isKnownCmp?: (canonizedRemainder: string) => boolean
|
|
1791
|
+
isKnownCmp?: (canonizedRemainder: string) => boolean,
|
|
1792
|
+
namespace?: string | null,
|
|
1534
1793
|
): string {
|
|
1535
|
-
let cleaned = name
|
|
1794
|
+
let cleaned = stripNamespace(name, namespace)
|
|
1536
1795
|
let stripped = false
|
|
1537
1796
|
|
|
1538
1797
|
// Version-tolerant known-schema probe. APIs that version their schemas name
|
|
@@ -2156,6 +2415,25 @@ function holdsOwnData(resprops: any): boolean {
|
|
|
2156
2415
|
}
|
|
2157
2416
|
|
|
2158
2417
|
|
|
2418
|
+
const ID_FIELD_RE = /^(id|ID|Id)$|_(id|ID)$|[a-z0-9](Id|ID)$/
|
|
2419
|
+
|
|
2420
|
+
// The array properties that list a response's records; none where the response
|
|
2421
|
+
// is a record that holds lists, as a signed-in user is: on a route its singular
|
|
2422
|
+
// literal names, it declares an identifier beside values of its own.
|
|
2423
|
+
function listingProps(resprops: any, pathStr: string): string[] {
|
|
2424
|
+
const arrays = keysof(resprops).filter((k: string) => 'array' === resprops[k]?.type)
|
|
2425
|
+
if (0 === arrays.length) {
|
|
2426
|
+
return arrays
|
|
2427
|
+
}
|
|
2428
|
+
const own = keysof(resprops).filter((k: string) => !isObjectSchema(resprops[k]) &&
|
|
2429
|
+
true !== propIsList(resprops[k]) && !isEnvelopeStatusProp(k) && !isEnvelopePageProp(k))
|
|
2430
|
+
const literals = guideParts(pathStr).filter((part: string) => !isParam(part))
|
|
2431
|
+
const last = snakify(literals[literals.length - 1] ?? '')
|
|
2432
|
+
const singular = '' !== last && depluralize(last) === last
|
|
2433
|
+
return singular && 3 <= own.length && own.some((k: string) => ID_FIELD_RE.test(k)) ? [] : arrays
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
|
|
2159
2437
|
// The component a response envelope carries: the resolved reference of the
|
|
2160
2438
|
// record strictEnvelopeProp unwraps to.
|
|
2161
2439
|
function envelopeItemRef(schema: any, opname: string): string | null {
|
|
@@ -2516,6 +2794,7 @@ export {
|
|
|
2516
2794
|
VALID_CANON,
|
|
2517
2795
|
CANON_ONE,
|
|
2518
2796
|
canonize,
|
|
2797
|
+
isParam,
|
|
2519
2798
|
canonizeField,
|
|
2520
2799
|
fieldName,
|
|
2521
2800
|
canonizeCmpName,
|
|
@@ -2527,6 +2806,10 @@ export {
|
|
|
2527
2806
|
slugToPascalCase,
|
|
2528
2807
|
transliterate,
|
|
2529
2808
|
cleanComponentName,
|
|
2809
|
+
wrapperOf,
|
|
2810
|
+
literalName,
|
|
2811
|
+
paramOf,
|
|
2812
|
+
paramNoun,
|
|
2530
2813
|
guideActive,
|
|
2531
2814
|
authExchangeOp,
|
|
2532
2815
|
specSecuredByDefault,
|
|
@@ -2551,6 +2834,13 @@ export {
|
|
|
2551
2834
|
relativizePath,
|
|
2552
2835
|
getModelPath,
|
|
2553
2836
|
sortedKeys,
|
|
2837
|
+
jsonContent,
|
|
2838
|
+
responseSchema,
|
|
2839
|
+
rangeResponse,
|
|
2840
|
+
cmpNamespace,
|
|
2841
|
+
stripNamespace,
|
|
2842
|
+
wordBreaks,
|
|
2843
|
+
PARAM_NOUN_SUFFIX_RE,
|
|
2554
2844
|
sortedEntries,
|
|
2555
2845
|
collapseScalarAllOf,
|
|
2556
2846
|
isEntityWrapperProp,
|
|
@@ -2558,6 +2848,7 @@ export {
|
|
|
2558
2848
|
itemEnvelopeTransform,
|
|
2559
2849
|
itemEnvelopeOf,
|
|
2560
2850
|
envelopeProp,
|
|
2851
|
+
strictEnvelopeProp,
|
|
2561
2852
|
recordLists,
|
|
2562
2853
|
singleEnvelope,
|
|
2563
2854
|
envelopeItemRef,
|
|
@@ -2566,6 +2857,7 @@ export {
|
|
|
2566
2857
|
pageTransform,
|
|
2567
2858
|
PAGE_ROLES,
|
|
2568
2859
|
answersPage,
|
|
2860
|
+
listingProps,
|
|
2569
2861
|
answersRecordMap,
|
|
2570
2862
|
propIsList,
|
|
2571
2863
|
mergedProperties,
|