@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/dist/utility.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ type PathMatch = (string[] & {
|
|
|
26
26
|
path: string;
|
|
27
27
|
});
|
|
28
28
|
declare function pathMatch(path: string | string[], expr: string): null | PathMatch;
|
|
29
|
+
declare function isParam(partStr: string): boolean;
|
|
30
|
+
declare function literalName(part: string): string;
|
|
31
|
+
declare function paramOf(part: string): string;
|
|
32
|
+
declare const PARAM_NOUN_SUFFIX_RE: RegExp;
|
|
33
|
+
declare function paramNoun(name: string): string;
|
|
29
34
|
declare function formatJSONIC(val?: any, opts?: {
|
|
30
35
|
hsepd?: number;
|
|
31
36
|
$?: boolean;
|
|
@@ -41,7 +46,8 @@ declare function validator(torig: undefined | string | string[]): any;
|
|
|
41
46
|
declare function nonNullType(type: any): string | undefined;
|
|
42
47
|
declare function transliterate(s: string): string;
|
|
43
48
|
declare function canonize(s: string): string;
|
|
44
|
-
declare function resplitFromCmp(entname: string, cmp: string, why: string[]): string;
|
|
49
|
+
declare function resplitFromCmp(entname: string, cmp: string, why: string[], breaks?: Record<string, string>): string;
|
|
50
|
+
declare function wordBreaks(def: any): Record<string, string>;
|
|
45
51
|
declare function canonizeField(s: string): string;
|
|
46
52
|
declare function fieldName(prop: string): string;
|
|
47
53
|
declare function stripSchemaNamespace(name: string): string;
|
|
@@ -62,6 +68,9 @@ declare function normalizeFieldName(s: string): string;
|
|
|
62
68
|
declare function canonizeParam(name: string): string;
|
|
63
69
|
declare function paramName(wire: string, renames?: Record<string, any> | null): string;
|
|
64
70
|
declare function ensureMinEntityName(name: string, existing: Record<string, any>): string;
|
|
71
|
+
declare function wrapperOf(name: string, known: string[]): string | null;
|
|
72
|
+
declare function cmpNamespace(def: any): string | null;
|
|
73
|
+
declare function stripNamespace(name: string, namespace?: string | null): string;
|
|
65
74
|
declare function stripOperationVerb(opid: string): string;
|
|
66
75
|
declare function guideActive(node: any): boolean;
|
|
67
76
|
declare function authExchangeOp(op: any, specSecured: boolean): {
|
|
@@ -69,7 +78,10 @@ declare function authExchangeOp(op: any, specSecured: boolean): {
|
|
|
69
78
|
response: string;
|
|
70
79
|
} | null;
|
|
71
80
|
declare function specSecuredByDefault(def: any): boolean;
|
|
72
|
-
declare function
|
|
81
|
+
declare function jsonContent(content: any): any;
|
|
82
|
+
declare function responseSchema(response: any): any;
|
|
83
|
+
declare function rangeResponse(responses: any): any;
|
|
84
|
+
declare function cleanComponentName(name: string, isKnownCmp?: (canonizedRemainder: string) => boolean, namespace?: string | null): string;
|
|
73
85
|
declare function warnOnError(where: string, warn: Warner, fn: Function, result?: any): any;
|
|
74
86
|
declare function debugpathOn(): boolean;
|
|
75
87
|
declare function debugpath(pathStr: string, methodName: string | null | undefined, ...args: any[]): void;
|
|
@@ -92,7 +104,9 @@ declare function itemEnvelopeOf(res: any): string | null;
|
|
|
92
104
|
declare function envelopeProp(resprops: any, opname: string, example?: any): string | null;
|
|
93
105
|
declare function recordLists(resprops: any): string[];
|
|
94
106
|
declare function singleEnvelope(resprops: any, opname: string): string | null;
|
|
107
|
+
declare function listingProps(resprops: any, pathStr: string): string[];
|
|
95
108
|
declare function envelopeItemRef(schema: any, opname: string): string | null;
|
|
109
|
+
declare function strictEnvelopeProp(props: any, opname: string): string | null;
|
|
96
110
|
declare function composedEnvelopeProp(schema: any, opname: string): string | null;
|
|
97
111
|
declare function pageRecords(schema: any): any;
|
|
98
112
|
declare const PAGE_ROLES: [string, string[]][];
|
|
@@ -111,4 +125,4 @@ declare function closedBodyTransform(schema: any): Record<string, string> | null
|
|
|
111
125
|
declare function requestWrapperOf(req: any): string | null;
|
|
112
126
|
declare function bodyRequestTransform(schema: any, names: string[]): any;
|
|
113
127
|
declare function firstSentence(text: string): string;
|
|
114
|
-
export { bodyRequestTransform, nom, getdlog, loadFile, formatJsonSrc, depluralize, pluralize, setCustomPlurals, clearCustomPlurals, find, capture, pathMatch, makeWarner, formatJSONIC, validator, isFileType, nonNullType, VALID_CANON, CANON_ONE, canonize, canonizeField, fieldName, canonizeCmpName, CMP_REF_RE, cmpRefName, READ_METHODS, stripSchemaNamespace, sanitizeSlug, slugToPascalCase, transliterate, cleanComponentName, guideActive, authExchangeOp, specSecuredByDefault, ensureMinEntityName, inferFieldType, normalizeFieldName, canonizeParam, paramName, humanTitle, foldName, prefixLeadingDigit, guardPrototypeName, guideParts, guidePath, stripOperationVerb, debugpath, debugpathOn, findPathsWithPrefix, writeFileSyncWarn, removeLegacyAon, warnOnError, relativizePath, getModelPath, sortedKeys, sortedEntries, collapseScalarAllOf, isEntityWrapperProp, itemEnvelopeKey, itemEnvelopeTransform, itemEnvelopeOf, envelopeProp, recordLists, singleEnvelope, envelopeItemRef, composedEnvelopeProp, pageRecords, pageTransform, PAGE_ROLES, answersPage, answersRecordMap, propIsList, mergedProperties, closedBodyTransform, requestWrapperOf, untaggedUnionBranches, scanUntaggedUnion, firstSentence, resplitFromCmp, };
|
|
128
|
+
export { bodyRequestTransform, nom, getdlog, loadFile, formatJsonSrc, depluralize, pluralize, setCustomPlurals, clearCustomPlurals, find, capture, pathMatch, makeWarner, formatJSONIC, validator, isFileType, nonNullType, VALID_CANON, CANON_ONE, canonize, isParam, canonizeField, fieldName, canonizeCmpName, CMP_REF_RE, cmpRefName, READ_METHODS, stripSchemaNamespace, sanitizeSlug, slugToPascalCase, transliterate, cleanComponentName, wrapperOf, literalName, paramOf, paramNoun, guideActive, authExchangeOp, specSecuredByDefault, ensureMinEntityName, inferFieldType, normalizeFieldName, canonizeParam, paramName, humanTitle, foldName, prefixLeadingDigit, guardPrototypeName, guideParts, guidePath, stripOperationVerb, debugpath, debugpathOn, findPathsWithPrefix, writeFileSyncWarn, removeLegacyAon, warnOnError, relativizePath, getModelPath, sortedKeys, jsonContent, responseSchema, rangeResponse, cmpNamespace, stripNamespace, wordBreaks, PARAM_NOUN_SUFFIX_RE, sortedEntries, collapseScalarAllOf, isEntityWrapperProp, itemEnvelopeKey, itemEnvelopeTransform, itemEnvelopeOf, envelopeProp, strictEnvelopeProp, recordLists, singleEnvelope, envelopeItemRef, composedEnvelopeProp, pageRecords, pageTransform, PAGE_ROLES, answersPage, listingProps, answersRecordMap, propIsList, mergedProperties, closedBodyTransform, requestWrapperOf, untaggedUnionBranches, scanUntaggedUnion, firstSentence, resplitFromCmp, };
|
package/dist/utility.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PAGE_ROLES = exports.sortedEntries = exports.sortedKeys = exports.READ_METHODS = exports.CMP_REF_RE = exports.CANON_ONE = exports.VALID_CANON = void 0;
|
|
6
|
+
exports.PAGE_ROLES = exports.sortedEntries = exports.PARAM_NOUN_SUFFIX_RE = exports.sortedKeys = exports.READ_METHODS = exports.CMP_REF_RE = exports.CANON_ONE = exports.VALID_CANON = void 0;
|
|
7
7
|
exports.bodyRequestTransform = bodyRequestTransform;
|
|
8
8
|
exports.nom = nom;
|
|
9
9
|
exports.getdlog = getdlog;
|
|
@@ -22,6 +22,7 @@ exports.validator = validator;
|
|
|
22
22
|
exports.isFileType = isFileType;
|
|
23
23
|
exports.nonNullType = nonNullType;
|
|
24
24
|
exports.canonize = canonize;
|
|
25
|
+
exports.isParam = isParam;
|
|
25
26
|
exports.canonizeField = canonizeField;
|
|
26
27
|
exports.fieldName = fieldName;
|
|
27
28
|
exports.canonizeCmpName = canonizeCmpName;
|
|
@@ -31,6 +32,10 @@ exports.sanitizeSlug = sanitizeSlug;
|
|
|
31
32
|
exports.slugToPascalCase = slugToPascalCase;
|
|
32
33
|
exports.transliterate = transliterate;
|
|
33
34
|
exports.cleanComponentName = cleanComponentName;
|
|
35
|
+
exports.wrapperOf = wrapperOf;
|
|
36
|
+
exports.literalName = literalName;
|
|
37
|
+
exports.paramOf = paramOf;
|
|
38
|
+
exports.paramNoun = paramNoun;
|
|
34
39
|
exports.guideActive = guideActive;
|
|
35
40
|
exports.authExchangeOp = authExchangeOp;
|
|
36
41
|
exports.specSecuredByDefault = specSecuredByDefault;
|
|
@@ -54,12 +59,19 @@ exports.removeLegacyAon = removeLegacyAon;
|
|
|
54
59
|
exports.warnOnError = warnOnError;
|
|
55
60
|
exports.relativizePath = relativizePath;
|
|
56
61
|
exports.getModelPath = getModelPath;
|
|
62
|
+
exports.jsonContent = jsonContent;
|
|
63
|
+
exports.responseSchema = responseSchema;
|
|
64
|
+
exports.rangeResponse = rangeResponse;
|
|
65
|
+
exports.cmpNamespace = cmpNamespace;
|
|
66
|
+
exports.stripNamespace = stripNamespace;
|
|
67
|
+
exports.wordBreaks = wordBreaks;
|
|
57
68
|
exports.collapseScalarAllOf = collapseScalarAllOf;
|
|
58
69
|
exports.isEntityWrapperProp = isEntityWrapperProp;
|
|
59
70
|
exports.itemEnvelopeKey = itemEnvelopeKey;
|
|
60
71
|
exports.itemEnvelopeTransform = itemEnvelopeTransform;
|
|
61
72
|
exports.itemEnvelopeOf = itemEnvelopeOf;
|
|
62
73
|
exports.envelopeProp = envelopeProp;
|
|
74
|
+
exports.strictEnvelopeProp = strictEnvelopeProp;
|
|
63
75
|
exports.recordLists = recordLists;
|
|
64
76
|
exports.singleEnvelope = singleEnvelope;
|
|
65
77
|
exports.envelopeItemRef = envelopeItemRef;
|
|
@@ -67,6 +79,7 @@ exports.composedEnvelopeProp = composedEnvelopeProp;
|
|
|
67
79
|
exports.pageRecords = pageRecords;
|
|
68
80
|
exports.pageTransform = pageTransform;
|
|
69
81
|
exports.answersPage = answersPage;
|
|
82
|
+
exports.listingProps = listingProps;
|
|
70
83
|
exports.answersRecordMap = answersRecordMap;
|
|
71
84
|
exports.propIsList = propIsList;
|
|
72
85
|
exports.mergedProperties = mergedProperties;
|
|
@@ -200,11 +213,15 @@ const IRREGULARS = Object.assign(Object.create(null), {
|
|
|
200
213
|
'avalanches': 'avalanche',
|
|
201
214
|
'axes': 'axis',
|
|
202
215
|
'bases': 'base',
|
|
216
|
+
'brownies': 'brownie',
|
|
203
217
|
'caches': 'cache',
|
|
218
|
+
'calories': 'calorie',
|
|
204
219
|
'canoes': 'canoe',
|
|
205
220
|
'cases': 'case',
|
|
206
221
|
'children': 'child',
|
|
207
222
|
'cliches': 'cliche',
|
|
223
|
+
'climaxes': 'climax',
|
|
224
|
+
'cookies': 'cookie',
|
|
208
225
|
'courses': 'course',
|
|
209
226
|
'creches': 'creche',
|
|
210
227
|
'crises': 'crisis',
|
|
@@ -216,17 +233,21 @@ const IRREGULARS = Object.assign(Object.create(null), {
|
|
|
216
233
|
'douches': 'douche',
|
|
217
234
|
'enterprises': 'enterprise',
|
|
218
235
|
'exercises': 'exercise',
|
|
236
|
+
'faxes': 'fax',
|
|
219
237
|
'feet': 'foot',
|
|
220
238
|
'fish': 'fish',
|
|
221
239
|
'franchises': 'franchise',
|
|
240
|
+
'freebies': 'freebie',
|
|
222
241
|
'furnaces': 'furnace',
|
|
223
242
|
'geese': 'goose',
|
|
243
|
+
'goalies': 'goalie',
|
|
224
244
|
'headaches': 'headache',
|
|
245
|
+
'hoodies': 'hoodie',
|
|
225
246
|
'horses': 'horse',
|
|
226
247
|
'hoses': 'hose',
|
|
227
248
|
'houses': 'house',
|
|
228
249
|
'indices': 'index',
|
|
229
|
-
'
|
|
250
|
+
'lenses': 'lens',
|
|
230
251
|
'licenses': 'license',
|
|
231
252
|
'matrices': 'matrix',
|
|
232
253
|
'men': 'man',
|
|
@@ -235,6 +256,7 @@ const IRREGULARS = Object.assign(Object.create(null), {
|
|
|
235
256
|
'moustaches': 'moustache',
|
|
236
257
|
'movies': 'movie',
|
|
237
258
|
'mustaches': 'mustache',
|
|
259
|
+
'newbies': 'newbie',
|
|
238
260
|
'niches': 'niche',
|
|
239
261
|
'noses': 'nose',
|
|
240
262
|
'notices': 'notice',
|
|
@@ -246,6 +268,7 @@ const IRREGULARS = Object.assign(Object.create(null), {
|
|
|
246
268
|
'pauses': 'pause',
|
|
247
269
|
'phases': 'phase',
|
|
248
270
|
'phrases': 'phrase',
|
|
271
|
+
'pickaxes': 'pickaxe',
|
|
249
272
|
'practices': 'practice',
|
|
250
273
|
'premises': 'premise',
|
|
251
274
|
'promises': 'promise',
|
|
@@ -254,20 +277,27 @@ const IRREGULARS = Object.assign(Object.create(null), {
|
|
|
254
277
|
'purses': 'purse',
|
|
255
278
|
'quizzes': 'quiz',
|
|
256
279
|
'releases': 'release',
|
|
280
|
+
'rookies': 'rookie',
|
|
257
281
|
'roses': 'rose',
|
|
258
282
|
'people': 'person',
|
|
259
283
|
'phenomena': 'phenomenon',
|
|
284
|
+
'selfies': 'selfie',
|
|
260
285
|
'series': 'series',
|
|
261
286
|
'sheep': 'sheep',
|
|
262
287
|
'shoes': 'shoe',
|
|
288
|
+
'smoothies': 'smoothie',
|
|
263
289
|
'sources': 'source',
|
|
264
290
|
'species': 'species',
|
|
291
|
+
'syntaxes': 'syntax',
|
|
292
|
+
'taxes': 'tax',
|
|
293
|
+
'taxis': 'taxi',
|
|
265
294
|
'teeth': 'tooth',
|
|
266
295
|
'theses': 'thesis',
|
|
267
296
|
'verses': 'verse',
|
|
268
297
|
'vertices': 'vertex',
|
|
269
298
|
'women': 'woman',
|
|
270
299
|
'yes': 'yes',
|
|
300
|
+
'zombies': 'zombie',
|
|
271
301
|
});
|
|
272
302
|
// The stems whose -ves plural comes from -fe (knives) or -f (wolves). The
|
|
273
303
|
// -fe stems match the whole word, since olives is not the plural of olife.
|
|
@@ -281,6 +311,8 @@ const F_PLURAL_STEMS = [
|
|
|
281
311
|
// insertion-order iteration. Both happen to round-trip correctly
|
|
282
312
|
// today, but the sort makes any future entry safe by construction.
|
|
283
313
|
const IRREGULAR_KEYS = Object.keys(IRREGULARS).sort((a, b) => b.length - a.length);
|
|
314
|
+
// Singular nouns that end in s, kept whole, as every -sis noun is (analysis).
|
|
315
|
+
const S_SINGULARS = ['alias', 'atlas', 'axis', 'bias', 'canvas', 'lens', 'news'];
|
|
284
316
|
// Nouns in -o whose plural takes -es; the rest take -s (photos).
|
|
285
317
|
const OES_NOUNS = ['echo', 'embargo', 'hero', 'potato', 'tomato', 'torpedo', 'veto'];
|
|
286
318
|
function matchCase(source, target) {
|
|
@@ -350,6 +382,9 @@ function depluralize(word) {
|
|
|
350
382
|
return word.slice(0, cut) + matchCase(word.slice(cut), IRREGULARS[ending]);
|
|
351
383
|
}
|
|
352
384
|
}
|
|
385
|
+
if (lower.endsWith('sis') || S_SINGULARS.some((ending) => lower.endsWith(ending))) {
|
|
386
|
+
return word;
|
|
387
|
+
}
|
|
353
388
|
// Rules for regular plurals (applied in order). The -ies and -ves
|
|
354
389
|
// rules add a letter, so they need to match the case of the dropped
|
|
355
390
|
// suffix; all other rules just slice and inherit the caller's case.
|
|
@@ -397,9 +432,11 @@ function depluralize(word) {
|
|
|
397
432
|
lower.endsWith('shes') || lower.endsWith('ches')) {
|
|
398
433
|
return word.slice(0, -2);
|
|
399
434
|
}
|
|
435
|
+
// A trailing s after a digit is part of a numeronym (k8s), not a plural.
|
|
400
436
|
if (lower.endsWith('s') &&
|
|
401
437
|
!lower.endsWith('ss') &&
|
|
402
438
|
!lower.endsWith('us') &&
|
|
439
|
+
!/[0-9]s$/.test(lower) &&
|
|
403
440
|
word.length > 3) {
|
|
404
441
|
return word.slice(0, -1);
|
|
405
442
|
}
|
|
@@ -606,7 +643,7 @@ function pathMatch(path, expr) {
|
|
|
606
643
|
if (null == path) {
|
|
607
644
|
return null;
|
|
608
645
|
}
|
|
609
|
-
const parts =
|
|
646
|
+
const parts = Array.isArray(path) ? path.filter(p => '' !== p) : guideParts(path);
|
|
610
647
|
const res = [];
|
|
611
648
|
res.index = -1;
|
|
612
649
|
res.expr = expr;
|
|
@@ -679,8 +716,33 @@ function pathMatch(path, expr) {
|
|
|
679
716
|
}
|
|
680
717
|
return null;
|
|
681
718
|
}
|
|
719
|
+
// A placeholder with any dot or extension it carries: `.{ext}`, `{api}.json`.
|
|
682
720
|
function isParam(partStr) {
|
|
683
|
-
|
|
721
|
+
if (null == partStr) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
const part = partStr.replace(/^\./, '').replace(/\}\.[A-Za-z0-9]+$/, '}');
|
|
725
|
+
return '{' === part[0] && '}' === part[part.length - 1];
|
|
726
|
+
}
|
|
727
|
+
// A trailing word that names a module rather than a resource.
|
|
728
|
+
const MODULE_WORDS = ['api', 'controller', 'service', 'resource', 'endpoint'];
|
|
729
|
+
// The entity name a path literal gives: canonized, less a trailing module
|
|
730
|
+
// word when another word remains, as `GadgetsApi` names gadget.
|
|
731
|
+
function literalName(part) {
|
|
732
|
+
const name = canonize(part);
|
|
733
|
+
const at = name.lastIndexOf('_');
|
|
734
|
+
return 0 < at && MODULE_WORDS.includes(name.slice(at + 1)) ?
|
|
735
|
+
depluralize(name.slice(0, at)) : name;
|
|
736
|
+
}
|
|
737
|
+
// The name a placeholder part carries, as `{id}.json` carries id: '' for none.
|
|
738
|
+
function paramOf(part) {
|
|
739
|
+
const m = part.match(/\{([^}]+)\}/);
|
|
740
|
+
return null == m ? '' : m[1];
|
|
741
|
+
}
|
|
742
|
+
const PARAM_NOUN_SUFFIX_RE = /_(name|id|key|code|slug|number|uuid)$/;
|
|
743
|
+
exports.PARAM_NOUN_SUFFIX_RE = PARAM_NOUN_SUFFIX_RE;
|
|
744
|
+
function paramNoun(name) {
|
|
745
|
+
return canonizeParam(name).replace(PARAM_NOUN_SUFFIX_RE, '');
|
|
684
746
|
}
|
|
685
747
|
function formatJSONIC(val, opts) {
|
|
686
748
|
if (undefined === val)
|
|
@@ -926,6 +988,8 @@ function nonNullType(type) {
|
|
|
926
988
|
return 1 === members.length && 'string' === typeof members[0] ? members[0] : undefined;
|
|
927
989
|
}
|
|
928
990
|
const FILE_EXT_RE = /\.(php|json|txt|png|jpg|jpeg|gif|svg|xml|html|csv|yml|yaml|md)$/i;
|
|
991
|
+
// Trailing placeholders, dotted or fused: `pets.{format}`, `notes{ext}`.
|
|
992
|
+
const PLACEHOLDER_EXT_RE = /(\.?\{[^}]*\})+$/;
|
|
929
993
|
function transliterate(s) {
|
|
930
994
|
return s.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
931
995
|
}
|
|
@@ -941,6 +1005,7 @@ function canonize(s) {
|
|
|
941
1005
|
return cached;
|
|
942
1006
|
const deacronymed = transliterate(s)
|
|
943
1007
|
.replace(FILE_EXT_RE, '')
|
|
1008
|
+
.replace(PLACEHOLDER_EXT_RE, '')
|
|
944
1009
|
.replace(ACRONYM_PLURAL_RE, (_m, run) => run[0] + run.slice(1).toLowerCase() + 's');
|
|
945
1010
|
const out = depluralize((0, jostraca_1.snakify)(deacronymed))
|
|
946
1011
|
.replace(/[^a-zA-Z_0-9]/g, '');
|
|
@@ -948,27 +1013,68 @@ function canonize(s) {
|
|
|
948
1013
|
return out;
|
|
949
1014
|
}
|
|
950
1015
|
const CANONIZE_FIELD_CACHE = new Map();
|
|
951
|
-
function resplitFromCmp(entname, cmp, why) {
|
|
1016
|
+
function resplitFromCmp(entname, cmp, why, breaks) {
|
|
952
1017
|
if (null == entname || '' === entname || entname.includes('_')) {
|
|
953
1018
|
return entname;
|
|
954
1019
|
}
|
|
955
|
-
if (null
|
|
956
|
-
|
|
1020
|
+
if (null != cmp && '' !== cmp && cmp.includes('_')) {
|
|
1021
|
+
const seg = cmp.split('_');
|
|
1022
|
+
let acc = '';
|
|
1023
|
+
for (let i = 0; i < seg.length && acc.length < entname.length; i++) {
|
|
1024
|
+
acc += seg[i];
|
|
1025
|
+
if (acc === entname) {
|
|
1026
|
+
const split = seg.slice(0, i + 1).join('_');
|
|
1027
|
+
why.push('resplit-from-cmp=' + split);
|
|
1028
|
+
return split;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const split = breaks?.[entname];
|
|
1033
|
+
if (null != split) {
|
|
1034
|
+
why.push('word-break=' + split);
|
|
1035
|
+
return split;
|
|
957
1036
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1037
|
+
return entname;
|
|
1038
|
+
}
|
|
1039
|
+
// Multi-word runs from tags, operationIds and component names, keyed by their
|
|
1040
|
+
// letters; where runs disagree, the first in sorted order.
|
|
1041
|
+
function wordBreaks(def) {
|
|
1042
|
+
const names = [];
|
|
1043
|
+
for (const tag of Array.isArray(def?.tags) ? def.tags : []) {
|
|
1044
|
+
names.push(canonize(String(tag?.name ?? '')));
|
|
1045
|
+
}
|
|
1046
|
+
for (const pathdef of Object.values(def?.paths ?? {})) {
|
|
1047
|
+
for (const opdef of Object.values(pathdef ?? {})) {
|
|
1048
|
+
if (null == opdef || 'object' !== typeof opdef || Array.isArray(opdef)) {
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
for (const tag of Array.isArray(opdef.tags) ? opdef.tags : []) {
|
|
1052
|
+
names.push(canonize(String(tag)));
|
|
1053
|
+
}
|
|
1054
|
+
if ('string' === typeof opdef.operationId) {
|
|
1055
|
+
names.push(canonize(opdef.operationId));
|
|
1056
|
+
}
|
|
966
1057
|
}
|
|
967
|
-
|
|
968
|
-
|
|
1058
|
+
}
|
|
1059
|
+
for (const name of Object.keys(def?.components?.schemas ?? def?.definitions ?? {})) {
|
|
1060
|
+
names.push(canonizeCmpName(name));
|
|
1061
|
+
}
|
|
1062
|
+
const found = Object.create(null);
|
|
1063
|
+
for (const name of names) {
|
|
1064
|
+
const words = name.split('_').filter((word) => '' !== word);
|
|
1065
|
+
for (let i = 0; i < words.length; i++) {
|
|
1066
|
+
for (let j = i + 2; j <= words.length; j++) {
|
|
1067
|
+
const run = [...words.slice(i, j - 1), depluralize(words[j - 1])];
|
|
1068
|
+
const key = run.join('');
|
|
1069
|
+
(found[key] = found[key] ?? []).push(run.join('_'));
|
|
1070
|
+
}
|
|
969
1071
|
}
|
|
970
1072
|
}
|
|
971
|
-
|
|
1073
|
+
const breaks = Object.create(null);
|
|
1074
|
+
for (const key of sortedKeys(found)) {
|
|
1075
|
+
breaks[key] = [...found[key]].sort()[0];
|
|
1076
|
+
}
|
|
1077
|
+
return breaks;
|
|
972
1078
|
}
|
|
973
1079
|
function canonizeField(s) {
|
|
974
1080
|
if (null == s || '' === s)
|
|
@@ -1024,9 +1130,11 @@ const FORMAT_EXTENSIONS = new Set([
|
|
|
1024
1130
|
'json', 'xml', 'csv', 'tsv', 'yaml', 'yml', 'txt', 'html', 'htm', 'rss',
|
|
1025
1131
|
'atom', 'jsonl', 'ndjson', 'geojson',
|
|
1026
1132
|
]);
|
|
1027
|
-
// A route segment as the guide reads it: {id}.json
|
|
1028
|
-
// data.{format} are repos and data, and a format alone (json)
|
|
1029
|
-
|
|
1133
|
+
// A route segment as the guide reads it: {id}.json and ${id} are {id},
|
|
1134
|
+
// repos.json and data.{format} are repos and data, and a format alone (json)
|
|
1135
|
+
// names nothing.
|
|
1136
|
+
function guideSegment(seg0) {
|
|
1137
|
+
const seg = seg0.replace(/\$\{/g, '{');
|
|
1030
1138
|
const held = seg.match(/^(\{[^}]+\})\.(?:[A-Za-z0-9]+|\{[^}]+\})$/);
|
|
1031
1139
|
if (null != held)
|
|
1032
1140
|
return held[1];
|
|
@@ -1036,9 +1144,12 @@ function guideSegment(seg) {
|
|
|
1036
1144
|
}
|
|
1037
1145
|
return FORMAT_EXTENSIONS.has(seg.toLowerCase()) ? null : seg;
|
|
1038
1146
|
}
|
|
1039
|
-
// The guide's parts of a route; a route
|
|
1147
|
+
// The guide's parts of a route, query and fragment cut; a route that is all
|
|
1148
|
+
// fragment, or of formats alone, keeps them.
|
|
1040
1149
|
function guideParts(path) {
|
|
1041
|
-
const
|
|
1150
|
+
const split = (route) => route.replace(/\?.*$/, '').split('/').filter((p) => '' !== p);
|
|
1151
|
+
const cut = split(path.replace(/#.*$/, ''));
|
|
1152
|
+
const parts = 0 === cut.length ? split(path) : cut;
|
|
1042
1153
|
const kept = parts.map(guideSegment).filter((p) => null != p);
|
|
1043
1154
|
return 0 === kept.length ? parts : kept;
|
|
1044
1155
|
}
|
|
@@ -1202,6 +1313,59 @@ function ensureMinEntityName(name, existing) {
|
|
|
1202
1313
|
}
|
|
1203
1314
|
return padded;
|
|
1204
1315
|
}
|
|
1316
|
+
const WRAPPER_WORDS = [
|
|
1317
|
+
'response', 'result', 'ok', 'envelope', 'wrapper', 'payload', 'page', 'paginated',
|
|
1318
|
+
'list', 'collection', 'data', 'body', 'output', 'reply',
|
|
1319
|
+
];
|
|
1320
|
+
// The component a wrapper-shaped name wraps, by wrapper words beside it or a
|
|
1321
|
+
// shared wrapper-word prefix naming no component: null for no wrapper, '' for
|
|
1322
|
+
// a wrapper of nothing nameable.
|
|
1323
|
+
function wrapperOf(name, known) {
|
|
1324
|
+
const words = name.split('_').filter((w) => '' !== w);
|
|
1325
|
+
// A name of the form noun-for-parent-response, or noun-for-parent once the
|
|
1326
|
+
// response suffix is cleaned away, wraps the noun; `per` reads as `for`.
|
|
1327
|
+
const forAt = words.findIndex((word) => 'for' === word || 'per' === word);
|
|
1328
|
+
if (0 < forAt && forAt < words.length - 1) {
|
|
1329
|
+
const held = depluralize(words.slice(0, forAt).join('_'));
|
|
1330
|
+
if (known.includes(held)) {
|
|
1331
|
+
return held;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
let inner = null;
|
|
1335
|
+
let at = -1;
|
|
1336
|
+
for (const k of known) {
|
|
1337
|
+
const kw = k.split('_').filter((w) => '' !== w);
|
|
1338
|
+
if (k === name || 0 === kw.length || (null != inner && kw.length <= inner.split('_').length)) {
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
for (let i = 0; i + kw.length <= words.length; i++) {
|
|
1342
|
+
if (kw.every((w, j) => w === words[i + j])) {
|
|
1343
|
+
inner = k;
|
|
1344
|
+
at = i;
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (null != inner) {
|
|
1350
|
+
const kw = inner.split('_').length;
|
|
1351
|
+
const rest = [...words.slice(0, at), ...words.slice(at + kw)];
|
|
1352
|
+
if (0 < rest.length && rest.every((w) => WRAPPER_WORDS.includes(w))) {
|
|
1353
|
+
return inner;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
const unversioned = known.map((k) => k.replace(/_v\d+$/, ''));
|
|
1357
|
+
for (let n = words.length - 1; 2 <= n; n--) {
|
|
1358
|
+
const prefix = words.slice(0, n).join('_');
|
|
1359
|
+
if (unversioned.includes(prefix)) {
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
const members = known.filter((k) => k !== name && k.startsWith(prefix + '_')).length;
|
|
1363
|
+
if (2 <= members && words.slice(0, n).some((w) => WRAPPER_WORDS.includes(w))) {
|
|
1364
|
+
return inner ?? '';
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1205
1369
|
// Unconditional suffixes: framework noise, always stripped.
|
|
1206
1370
|
const CMP_SUFFIXES = ['_rest_controller', '_controller', '_response', '_request'];
|
|
1207
1371
|
// Longest first: the first suffix a name ends with is the only one tried.
|
|
@@ -1215,6 +1379,48 @@ const CMP_RESULT_VERBS = [
|
|
|
1215
1379
|
'get', 'edit', 'resolve', 'rotate', 'search', 'add',
|
|
1216
1380
|
];
|
|
1217
1381
|
const CMP_PREFIXES = ['get_', 'post_', 'put_', 'delete_', 'patch_'];
|
|
1382
|
+
// The leading word run more than half the components, and at least two,
|
|
1383
|
+
// share; none where a path literal, a whole component name or a wrapper word
|
|
1384
|
+
// holds it.
|
|
1385
|
+
function cmpNamespace(def) {
|
|
1386
|
+
const schemas = def?.components?.schemas ?? def?.definitions;
|
|
1387
|
+
const names = sortedKeys(schemas).map((name) => canonizeCmpName(name).split('_').filter((word) => '' !== word));
|
|
1388
|
+
const run = [];
|
|
1389
|
+
let shared = 0;
|
|
1390
|
+
for (;;) {
|
|
1391
|
+
const at = run.length;
|
|
1392
|
+
const tally = Object.create(null);
|
|
1393
|
+
for (const words of names) {
|
|
1394
|
+
if (at + 1 < words.length && run.every((word, i) => words[i] === word)) {
|
|
1395
|
+
tally[words[at]] = (tally[words[at]] ?? 0) + 1;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
const next = sortedKeys(tally).find((word) => 0 === at ? names.length < 2 * tally[word] : shared === tally[word]);
|
|
1399
|
+
if (null == next) {
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
run.push(next);
|
|
1403
|
+
shared = tally[next];
|
|
1404
|
+
}
|
|
1405
|
+
if (shared < 2 || run.some((word) => WRAPPER_WORDS.includes(word)) ||
|
|
1406
|
+
names.some((words) => words.join('_') === run.join('_'))) {
|
|
1407
|
+
return null;
|
|
1408
|
+
}
|
|
1409
|
+
const held = run.map((word) => depluralize(word));
|
|
1410
|
+
const literals = Object.keys(def?.paths ?? {}).flatMap((p) => guideParts(p))
|
|
1411
|
+
.filter((part) => !isParam(part))
|
|
1412
|
+
.map((part) => literalName(part).split('_').map((word) => depluralize(word)));
|
|
1413
|
+
const holds = (words) => words.some((_, i) => i + held.length <= words.length && held.every((word, j) => words[i + j] === word));
|
|
1414
|
+
return literals.some(holds) ? null : run.join('_');
|
|
1415
|
+
}
|
|
1416
|
+
// A name less its namespace, when a name remains.
|
|
1417
|
+
function stripNamespace(name, namespace) {
|
|
1418
|
+
if (null == namespace || !name.startsWith(namespace + '_')) {
|
|
1419
|
+
return name;
|
|
1420
|
+
}
|
|
1421
|
+
const rest = name.slice(namespace.length + 1);
|
|
1422
|
+
return rest.replace(/_/g, '').length < 3 ? name : rest;
|
|
1423
|
+
}
|
|
1218
1424
|
const OPERATION_VERBS = [
|
|
1219
1425
|
...CMP_RESULT_VERBS, 'post', 'put', 'patch', 'fetch', 'find', 'retrieve', 'read', 'add',
|
|
1220
1426
|
];
|
|
@@ -1275,11 +1481,40 @@ function specSecuredByDefault(def) {
|
|
|
1275
1481
|
// The 2xx body schema, OpenAPI 3 (`content`) or Swagger 2 (`schema`).
|
|
1276
1482
|
function successResponseSchema(responses) {
|
|
1277
1483
|
const res = responses?.['200'] ?? responses?.[200] ??
|
|
1278
|
-
responses?.['201'] ?? responses?.[201];
|
|
1484
|
+
responses?.['201'] ?? responses?.[201] ?? rangeResponse(responses);
|
|
1279
1485
|
if (null == res) {
|
|
1280
1486
|
return null;
|
|
1281
1487
|
}
|
|
1282
|
-
return res
|
|
1488
|
+
return responseSchema(res) ?? null;
|
|
1489
|
+
}
|
|
1490
|
+
const JSON_MEDIA_RE = /^[^/;]+\/([^;]*\+)?json\s*(;.*)?$/i;
|
|
1491
|
+
// The content a response is read from: JSON first, then any other JSON type,
|
|
1492
|
+
// then the any-type range unless it declares binary content.
|
|
1493
|
+
function jsonContent(content) {
|
|
1494
|
+
if (null == content || 'object' !== typeof content) {
|
|
1495
|
+
return undefined;
|
|
1496
|
+
}
|
|
1497
|
+
if (null != content['application/json']) {
|
|
1498
|
+
return content['application/json'];
|
|
1499
|
+
}
|
|
1500
|
+
const json = sortedKeys(content).find((media) => JSON_MEDIA_RE.test(media));
|
|
1501
|
+
if (null != json) {
|
|
1502
|
+
return content[json];
|
|
1503
|
+
}
|
|
1504
|
+
const schema = content['*/*']?.schema;
|
|
1505
|
+
return 'string' === schema?.type && 'binary' === schema?.format ? undefined : content['*/*'];
|
|
1506
|
+
}
|
|
1507
|
+
// A response's schema, OpenAPI 3 (`content`) or Swagger 2 (`schema`).
|
|
1508
|
+
function responseSchema(response) {
|
|
1509
|
+
return jsonContent(response?.content)?.schema ?? response?.schema;
|
|
1510
|
+
}
|
|
1511
|
+
// A range code answers for the success codes a definition does not name.
|
|
1512
|
+
function rangeResponse(responses) {
|
|
1513
|
+
if (null == responses || null != responses['200'] || null != responses['201'] ||
|
|
1514
|
+
null != responses['202']) {
|
|
1515
|
+
return undefined;
|
|
1516
|
+
}
|
|
1517
|
+
return responses['2XX'] ?? responses['2xx'];
|
|
1283
1518
|
}
|
|
1284
1519
|
function requestBodySchema(requestBody) {
|
|
1285
1520
|
if (null == requestBody) {
|
|
@@ -1311,8 +1546,8 @@ function firstFieldMatch(props, names) {
|
|
|
1311
1546
|
}
|
|
1312
1547
|
return null;
|
|
1313
1548
|
}
|
|
1314
|
-
function cleanComponentName(name, isKnownCmp) {
|
|
1315
|
-
let cleaned = name;
|
|
1549
|
+
function cleanComponentName(name, isKnownCmp, namespace) {
|
|
1550
|
+
let cleaned = stripNamespace(name, namespace);
|
|
1316
1551
|
let stripped = false;
|
|
1317
1552
|
// Version-tolerant known-schema probe. APIs that version their schemas name
|
|
1318
1553
|
// the base type SeverityV1 / IncidentV2, so a guard asking only for
|
|
@@ -1805,6 +2040,22 @@ function holdsOwnData(resprops) {
|
|
|
1805
2040
|
return (0, struct_1.keysof)(resprops).some((k) => !isObjectSchema(resprops[k]) &&
|
|
1806
2041
|
true !== propIsList(resprops[k]) && !isEnvelopeStatusProp(k) && !isEnvelopePageProp(k));
|
|
1807
2042
|
}
|
|
2043
|
+
const ID_FIELD_RE = /^(id|ID|Id)$|_(id|ID)$|[a-z0-9](Id|ID)$/;
|
|
2044
|
+
// The array properties that list a response's records; none where the response
|
|
2045
|
+
// is a record that holds lists, as a signed-in user is: on a route its singular
|
|
2046
|
+
// literal names, it declares an identifier beside values of its own.
|
|
2047
|
+
function listingProps(resprops, pathStr) {
|
|
2048
|
+
const arrays = (0, struct_1.keysof)(resprops).filter((k) => 'array' === resprops[k]?.type);
|
|
2049
|
+
if (0 === arrays.length) {
|
|
2050
|
+
return arrays;
|
|
2051
|
+
}
|
|
2052
|
+
const own = (0, struct_1.keysof)(resprops).filter((k) => !isObjectSchema(resprops[k]) &&
|
|
2053
|
+
true !== propIsList(resprops[k]) && !isEnvelopeStatusProp(k) && !isEnvelopePageProp(k));
|
|
2054
|
+
const literals = guideParts(pathStr).filter((part) => !isParam(part));
|
|
2055
|
+
const last = (0, jostraca_1.snakify)(literals[literals.length - 1] ?? '');
|
|
2056
|
+
const singular = '' !== last && depluralize(last) === last;
|
|
2057
|
+
return singular && 3 <= own.length && own.some((k) => ID_FIELD_RE.test(k)) ? [] : arrays;
|
|
2058
|
+
}
|
|
1808
2059
|
// The component a response envelope carries: the resolved reference of the
|
|
1809
2060
|
// record strictEnvelopeProp unwraps to.
|
|
1810
2061
|
function envelopeItemRef(schema, opname) {
|