@skmtc/core 0.33.0 → 0.35.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/esm/context/CoreContext.d.ts +8 -21
- package/esm/context/CoreContext.js +9 -22
- package/esm/context/GenerateContext.js +7 -7
- package/esm/context/ParseContext.d.ts +1 -1
- package/esm/context/ParseContext.js +2 -2
- package/esm/context/StackTrail.d.ts +30 -13
- package/esm/context/StackTrail.js +36 -14
- package/esm/context/generateTypes.d.ts +2 -2
- package/esm/context/generateTypes.js +5 -0
- package/esm/helpers/ResultsLog.d.ts +19 -181
- package/esm/helpers/ResultsLog.js +46 -205
- package/esm/parse/descriptiveFields.d.ts +36 -0
- package/esm/parse/descriptiveFields.js +56 -0
- package/esm/parse/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -0
- package/esm/parse/toComponentEntries.d.ts +29 -0
- package/esm/parse/toComponentEntries.js +31 -0
- package/esm/parse/toPresentInfo.d.ts +30 -0
- package/esm/parse/toPresentInfo.js +40 -0
- package/esm/parse/v3-0/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-0/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-0/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-0/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-0/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-0/info/toInfoV3.js +15 -4
- package/esm/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-0/tag/toTagsV3.js +7 -2
- package/esm/parse/v3-1/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-1/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-1/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-1/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-1/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-1/info/toInfoV3.js +15 -4
- package/esm/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-1/tag/toTagsV3.js +7 -2
- package/esm/parse/v3-2/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-2/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-2/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-2/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-2/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-2/info/toInfoV3.js +15 -4
- package/esm/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-2/tag/toTagsV3.js +14 -7
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts +8 -21
- package/script/context/CoreContext.js +9 -22
- package/script/context/GenerateContext.js +7 -7
- package/script/context/ParseContext.d.ts +1 -1
- package/script/context/ParseContext.js +2 -2
- package/script/context/StackTrail.d.ts +30 -13
- package/script/context/StackTrail.js +36 -14
- package/script/context/generateTypes.d.ts +2 -2
- package/script/context/generateTypes.js +5 -0
- package/script/helpers/ResultsLog.d.ts +19 -181
- package/script/helpers/ResultsLog.js +46 -208
- package/script/parse/descriptiveFields.d.ts +36 -0
- package/script/parse/descriptiveFields.js +95 -0
- package/script/parse/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +6 -0
- package/script/parse/toComponentEntries.d.ts +29 -0
- package/script/parse/toComponentEntries.js +35 -0
- package/script/parse/toPresentInfo.d.ts +30 -0
- package/script/parse/toPresentInfo.js +45 -0
- package/script/parse/v3-0/components/toComponentsV3.js +1 -1
- package/script/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-0/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-0/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-0/header/toHeadersV3.js +22 -1
- package/script/parse/v3-0/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-0/info/toInfoV3.js +15 -4
- package/script/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-0/tag/toTagsV3.js +7 -2
- package/script/parse/v3-1/components/toComponentsV3.js +1 -1
- package/script/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-1/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-1/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-1/header/toHeadersV3.js +22 -1
- package/script/parse/v3-1/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-1/info/toInfoV3.js +15 -4
- package/script/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-1/tag/toTagsV3.js +7 -2
- package/script/parse/v3-2/components/toComponentsV3.js +1 -1
- package/script/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-2/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-2/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-2/header/toHeadersV3.js +22 -1
- package/script/parse/v3-2/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-2/info/toInfoV3.js +15 -4
- package/script/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-2/tag/toTagsV3.js +14 -7
|
@@ -10,222 +10,72 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
13
|
var _ResultsLog_instances, _ResultsLog_results, _ResultsLog_incomingResultIsWorse;
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.ResultsLog = void 0;
|
|
19
|
-
const set_js_1 = __importDefault(require("lodash-es/set.js"));
|
|
20
16
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `ResultsLog` tracks the outcomes of code generation operations, maintaining
|
|
24
|
-
* a hierarchical structure of results organized by stack trail paths. It implements
|
|
25
|
-
* intelligent result prioritization, ensuring that more severe results (errors)
|
|
26
|
-
* take precedence over less severe ones (success, warnings) when multiple results
|
|
27
|
-
* exist for the same path.
|
|
28
|
-
*
|
|
29
|
-
* The class is designed to work with the SKMTC tracing system, using stack trail
|
|
30
|
-
* identifiers to organize results in a meaningful hierarchical structure that
|
|
31
|
-
* reflects the execution flow of the generation process.
|
|
32
|
-
*
|
|
33
|
-
* ## Key Features
|
|
34
|
-
*
|
|
35
|
-
* - **Result Prioritization**: Automatically prioritizes more severe results
|
|
36
|
-
* - **Hierarchical Organization**: Organizes results by stack trail paths
|
|
37
|
-
* - **Tree Structure**: Converts flat result logs into nested tree structures
|
|
38
|
-
* - **Duplicate Handling**: Prevents less severe results from overwriting more severe ones
|
|
39
|
-
*
|
|
40
|
-
* @example Basic usage
|
|
41
|
-
* ```typescript
|
|
42
|
-
* import { ResultsLog } from '@skmtc/core';
|
|
43
|
-
*
|
|
44
|
-
* const resultsLog = new ResultsLog();
|
|
45
|
-
*
|
|
46
|
-
* // Capture results from different parts of generation
|
|
47
|
-
* resultsLog.capture('models:User', 'success');
|
|
48
|
-
* resultsLog.capture('models:Product', 'error');
|
|
49
|
-
* resultsLog.capture('types:Status', 'success');
|
|
50
|
-
*
|
|
51
|
-
* // Convert to hierarchical structure
|
|
52
|
-
* const tree = resultsLog.toTree();
|
|
53
|
-
* console.log(tree);
|
|
54
|
-
* // {
|
|
55
|
-
* // models: {
|
|
56
|
-
* // User: 'success',
|
|
57
|
-
* // Product: 'error'
|
|
58
|
-
* // },
|
|
59
|
-
* // types: {
|
|
60
|
-
* // Status: 'success'
|
|
61
|
-
* // }
|
|
62
|
-
* // }
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* @example Result prioritization
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const resultsLog = new ResultsLog();
|
|
68
|
-
*
|
|
69
|
-
* // First capture a success
|
|
70
|
-
* resultsLog.capture('api:createUser', 'success');
|
|
71
|
-
*
|
|
72
|
-
* // Later encounter an error at the same path
|
|
73
|
-
* resultsLog.capture('api:createUser', 'error');
|
|
74
|
-
*
|
|
75
|
-
* // Error takes precedence
|
|
76
|
-
* const tree = resultsLog.toTree();
|
|
77
|
-
* console.log(tree.api.createUser); // 'error'
|
|
78
|
-
*
|
|
79
|
-
* // But success won't overwrite error
|
|
80
|
-
* resultsLog.capture('api:createUser', 'success');
|
|
81
|
-
* console.log(resultsLog.toTree().api.createUser); // Still 'error'
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* @example Complex nested paths
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const resultsLog = new ResultsLog();
|
|
87
|
-
*
|
|
88
|
-
* resultsLog.capture('generation:models:User:properties:name', 'success');
|
|
89
|
-
* resultsLog.capture('generation:models:User:properties:email', 'warning');
|
|
90
|
-
* resultsLog.capture('generation:models:Product:validation', 'error');
|
|
91
|
-
* resultsLog.capture('generation:operations:createUser', 'success');
|
|
17
|
+
* Records one result per stack trail and builds the `manifest.results` tree.
|
|
92
18
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* // {
|
|
96
|
-
* // generation: {
|
|
97
|
-
* // models: {
|
|
98
|
-
* // User: {
|
|
99
|
-
* // properties: {
|
|
100
|
-
* // name: 'success',
|
|
101
|
-
* // email: 'warning'
|
|
102
|
-
* // }
|
|
103
|
-
* // },
|
|
104
|
-
* // Product: {
|
|
105
|
-
* // validation: 'error'
|
|
106
|
-
* // }
|
|
107
|
-
* // },
|
|
108
|
-
* // operations: {
|
|
109
|
-
* // createUser: 'success'
|
|
110
|
-
* // }
|
|
111
|
-
* // }
|
|
112
|
-
* // }
|
|
113
|
-
* ```
|
|
19
|
+
* When several results are captured at the same trail, the most severe one
|
|
20
|
+
* wins (see `resultRankings`).
|
|
114
21
|
*
|
|
115
|
-
* @example
|
|
22
|
+
* @example
|
|
116
23
|
* ```typescript
|
|
117
|
-
*
|
|
118
|
-
* private resultsLog = new ResultsLog();
|
|
119
|
-
*
|
|
120
|
-
* generateModel(name: string, schema: OasSchema) {
|
|
121
|
-
* const stackPath = `models:${name}`;
|
|
122
|
-
*
|
|
123
|
-
* try {
|
|
124
|
-
* const model = this.processSchema(schema);
|
|
125
|
-
* this.resultsLog.capture(stackPath, 'success');
|
|
126
|
-
* return model;
|
|
127
|
-
* } catch (error) {
|
|
128
|
-
* this.resultsLog.capture(stackPath, 'error');
|
|
129
|
-
* throw error;
|
|
130
|
-
* }
|
|
131
|
-
* }
|
|
24
|
+
* const resultsLog = new ResultsLog()
|
|
132
25
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
26
|
+
* resultsLog.capture(new StackTrail(['generate', '/pets', 'get']), 'success')
|
|
27
|
+
* resultsLog.capture(new StackTrail(['generate', '/pets/{id}:archive', 'post']), 'error')
|
|
135
28
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* return null;
|
|
139
|
-
* }
|
|
140
|
-
*
|
|
141
|
-
* const result = this.processOperation(operation);
|
|
142
|
-
* this.resultsLog.capture(stackPath, 'success');
|
|
143
|
-
* return result;
|
|
144
|
-
* }
|
|
145
|
-
*
|
|
146
|
-
* getResults(): ResultsItem {
|
|
147
|
-
* return this.resultsLog.toTree();
|
|
148
|
-
* }
|
|
149
|
-
* }
|
|
29
|
+
* resultsLog.toTree()
|
|
30
|
+
* // { generate: { '/pets': { get: 'success' }, '/pets/{id}:archive': { post: 'error' } } }
|
|
150
31
|
* ```
|
|
151
32
|
*/
|
|
152
33
|
class ResultsLog {
|
|
153
|
-
/**
|
|
154
|
-
* Creates a new ResultsLog instance.
|
|
155
|
-
*
|
|
156
|
-
* Initializes an empty results tracking system ready to capture
|
|
157
|
-
* generation outcomes from various parts of the pipeline.
|
|
158
|
-
*/
|
|
159
34
|
constructor() {
|
|
160
35
|
_ResultsLog_instances.add(this);
|
|
36
|
+
/**
|
|
37
|
+
* Keyed by `StackTrail.toString()`. The key is one-to-one with the frames,
|
|
38
|
+
* except that `[]` and `['']` both give `''`.
|
|
39
|
+
*/
|
|
161
40
|
_ResultsLog_results.set(this, void 0);
|
|
162
|
-
__classPrivateFieldSet(this, _ResultsLog_results,
|
|
41
|
+
__classPrivateFieldSet(this, _ResultsLog_results, new Map(), "f");
|
|
163
42
|
}
|
|
164
43
|
/**
|
|
165
|
-
* Captures
|
|
166
|
-
*
|
|
167
|
-
* This method records the outcome of a generation operation, using intelligent
|
|
168
|
-
* prioritization to ensure that more severe results take precedence over less
|
|
169
|
-
* severe ones. For example, an error result will not be overwritten by a
|
|
170
|
-
* success result, but a success can be overwritten by an error.
|
|
171
|
-
*
|
|
172
|
-
* @param stackTrail - Colon-separated path identifying the operation location
|
|
173
|
-
* @param result - The result type to capture (error, warning, success, etc.)
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const resultsLog = new ResultsLog();
|
|
44
|
+
* Captures `result` at `stackTrail`, unless a more severe result is
|
|
45
|
+
* already recorded there.
|
|
178
46
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* resultsLog.capture('models:User:validation', 'warning');
|
|
182
|
-
* resultsLog.capture('operations:createUser', 'error');
|
|
183
|
-
* ```
|
|
47
|
+
* Stores a copy of the frames: `StackTrail.trace` pops the live array
|
|
48
|
+
* after its callback returns.
|
|
184
49
|
*/
|
|
185
50
|
capture(stackTrail, result) {
|
|
186
|
-
|
|
187
|
-
|
|
51
|
+
const key = stackTrail.toString();
|
|
52
|
+
if (__classPrivateFieldGet(this, _ResultsLog_instances, "m", _ResultsLog_incomingResultIsWorse).call(this, __classPrivateFieldGet(this, _ResultsLog_results, "f").get(key)?.result, result)) {
|
|
53
|
+
__classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames: [...stackTrail.stackTrail], result });
|
|
188
54
|
}
|
|
189
55
|
}
|
|
190
56
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* operations. This makes it easier to understand and process results in
|
|
196
|
-
* a structured way.
|
|
197
|
-
*
|
|
198
|
-
* @returns Nested object structure representing the results hierarchy
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```typescript
|
|
202
|
-
* const resultsLog = new ResultsLog();
|
|
203
|
-
* resultsLog.capture('api:models:User', 'success');
|
|
204
|
-
* resultsLog.capture('api:operations:getUser', 'error');
|
|
205
|
-
* resultsLog.capture('types:Status', 'success');
|
|
206
|
-
*
|
|
207
|
-
* const tree = resultsLog.toTree();
|
|
208
|
-
* console.log(tree);
|
|
209
|
-
* // {
|
|
210
|
-
* // api: {
|
|
211
|
-
* // models: {
|
|
212
|
-
* // User: 'success'
|
|
213
|
-
* // },
|
|
214
|
-
* // operations: {
|
|
215
|
-
* // getUser: 'error'
|
|
216
|
-
* // }
|
|
217
|
-
* // },
|
|
218
|
-
* // types: {
|
|
219
|
-
* // Status: 'success'
|
|
220
|
-
* // }
|
|
221
|
-
* // }
|
|
222
|
-
* ```
|
|
57
|
+
* Nests the captured results by their frames, one object level per frame.
|
|
58
|
+
* Frames are used as own-property keys verbatim, so a frame such as
|
|
59
|
+
* `constructor`, `toString` or `0` is a key like any other. A result
|
|
60
|
+
* captured at the empty trail has no key and is left out.
|
|
223
61
|
*/
|
|
224
62
|
toTree() {
|
|
225
63
|
const tree = {};
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
64
|
+
__classPrivateFieldGet(this, _ResultsLog_results, "f").forEach(({ frames, result }) => {
|
|
65
|
+
const leafFrame = frames.at(-1);
|
|
66
|
+
if (leafFrame === undefined) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const parent = frames.slice(0, -1).reduce((node, frame) => {
|
|
70
|
+
const existing = Object.hasOwn(node, frame) ? node[frame] : undefined;
|
|
71
|
+
if (typeof existing === 'object' && existing !== null && !Array.isArray(existing)) {
|
|
72
|
+
return existing;
|
|
73
|
+
}
|
|
74
|
+
const child = {};
|
|
75
|
+
defineOwn(node, frame, child);
|
|
76
|
+
return child;
|
|
77
|
+
}, tree);
|
|
78
|
+
defineOwn(parent, leafFrame, result);
|
|
229
79
|
});
|
|
230
80
|
return tree;
|
|
231
81
|
}
|
|
@@ -237,25 +87,13 @@ _ResultsLog_results = new WeakMap(), _ResultsLog_instances = new WeakSet(), _Res
|
|
|
237
87
|
}
|
|
238
88
|
return resultRankings[current] < resultRankings[incoming];
|
|
239
89
|
};
|
|
90
|
+
/** Writes an own, enumerable property, even for keys such as `__proto__`. */
|
|
91
|
+
const defineOwn = (node, key, value) => {
|
|
92
|
+
Object.defineProperty(node, key, { value, enumerable: true, writable: true, configurable: true });
|
|
93
|
+
};
|
|
240
94
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* This mapping defines the severity hierarchy used by the ResultsLog to determine
|
|
244
|
-
* which results should take precedence when multiple results are captured for the
|
|
245
|
-
* same path. Higher numbers indicate higher severity/priority.
|
|
246
|
-
*
|
|
247
|
-
* The ranking system ensures that critical issues (errors) are never masked by
|
|
248
|
-
* less important results (success), while still allowing for proper escalation
|
|
249
|
-
* when more severe conditions are encountered.
|
|
250
|
-
*
|
|
251
|
-
* @example Ranking hierarchy (high to low priority)
|
|
252
|
-
* ```
|
|
253
|
-
* error (50) - Critical failures that prevent generation
|
|
254
|
-
* warning (40) - Issues that allow generation but need attention
|
|
255
|
-
* success (30) - Normal successful completion
|
|
256
|
-
* skipped (20) - Operations that were intentionally bypassed
|
|
257
|
-
* notSupported (10) - Features not yet implemented
|
|
258
|
-
* ```
|
|
95
|
+
* Severity of each result type. A higher number replaces a lower one
|
|
96
|
+
* captured at the same trail.
|
|
259
97
|
*/
|
|
260
98
|
const resultRankings = {
|
|
261
99
|
error: 50,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
import { type OasExternalDocsData } from '../oas/externalDocs/externalDocsTypes.js';
|
|
4
|
+
export type ToTagListArgs<Tag> = {
|
|
5
|
+
tags: Tag[];
|
|
6
|
+
/** Trail that ends in the `tags` key. */
|
|
7
|
+
stackTrail: StackTrail;
|
|
8
|
+
context: ParseContextType;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Check the root `tags` field before its entries are parsed. Not an array:
|
|
12
|
+
* logs one `INVALID_TAG` warning and returns `undefined`, read as no tags.
|
|
13
|
+
*/
|
|
14
|
+
export declare const toTagList: <Tag>({ tags, stackTrail, context }: ToTagListArgs<Tag>) => Tag[] | undefined;
|
|
15
|
+
export type IsValidTagArgs = {
|
|
16
|
+
tag: unknown;
|
|
17
|
+
/** Trail that ends in the entry's index. */
|
|
18
|
+
stackTrail: StackTrail;
|
|
19
|
+
context: ParseContextType;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A tag entry must be a plain object with a string `name`. Any other entry
|
|
23
|
+
* logs one `INVALID_TAG` warning, and the caller leaves it out.
|
|
24
|
+
*/
|
|
25
|
+
export declare const isValidTag: ({ tag, stackTrail, context }: IsValidTagArgs) => boolean;
|
|
26
|
+
export type ToValidExternalDocsArgs = {
|
|
27
|
+
externalDocs: unknown;
|
|
28
|
+
/** Trail that ends in the `externalDocs` key. */
|
|
29
|
+
stackTrail: StackTrail;
|
|
30
|
+
context: ParseContextType;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Validate an `externalDocs` object. One that fails `oasExternalDocsData`
|
|
34
|
+
* logs one `INVALID_EXTERNAL_DOCS` warning and returns `undefined`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const toValidExternalDocs: ({ externalDocs, stackTrail, context }: ToValidExternalDocsArgs) => OasExternalDocsData | undefined;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.toValidExternalDocs = exports.isValidTag = exports.toTagList = void 0;
|
|
37
|
+
const v = __importStar(require("valibot"));
|
|
38
|
+
const isPlainObject_js_1 = require("./isPlainObject.js");
|
|
39
|
+
const externalDocsTypes_js_1 = require("../oas/externalDocs/externalDocsTypes.js");
|
|
40
|
+
/**
|
|
41
|
+
* Check the root `tags` field before its entries are parsed. Not an array:
|
|
42
|
+
* logs one `INVALID_TAG` warning and returns `undefined`, read as no tags.
|
|
43
|
+
*/
|
|
44
|
+
const toTagList = ({ tags, stackTrail, context }) => {
|
|
45
|
+
if (Array.isArray(tags)) {
|
|
46
|
+
return tags;
|
|
47
|
+
}
|
|
48
|
+
context.logIssueNoKey({
|
|
49
|
+
stackTrail,
|
|
50
|
+
parent: tags,
|
|
51
|
+
level: 'warning',
|
|
52
|
+
type: 'INVALID_TAG',
|
|
53
|
+
message: '"tags" must be an array; left out'
|
|
54
|
+
});
|
|
55
|
+
return undefined;
|
|
56
|
+
};
|
|
57
|
+
exports.toTagList = toTagList;
|
|
58
|
+
/**
|
|
59
|
+
* A tag entry must be a plain object with a string `name`. Any other entry
|
|
60
|
+
* logs one `INVALID_TAG` warning, and the caller leaves it out.
|
|
61
|
+
*/
|
|
62
|
+
const isValidTag = ({ tag, stackTrail, context }) => {
|
|
63
|
+
if ((0, isPlainObject_js_1.isPlainObject)(tag) && typeof tag.name === 'string') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
context.logIssueNoKey({
|
|
67
|
+
stackTrail,
|
|
68
|
+
parent: tag,
|
|
69
|
+
level: 'warning',
|
|
70
|
+
type: 'INVALID_TAG',
|
|
71
|
+
message: 'Tag is not an object with a string name; left out'
|
|
72
|
+
});
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
exports.isValidTag = isValidTag;
|
|
76
|
+
/**
|
|
77
|
+
* Validate an `externalDocs` object. One that fails `oasExternalDocsData`
|
|
78
|
+
* logs one `INVALID_EXTERNAL_DOCS` warning and returns `undefined`.
|
|
79
|
+
*/
|
|
80
|
+
const toValidExternalDocs = ({ externalDocs, stackTrail, context }) => {
|
|
81
|
+
const result = v.safeParse(externalDocsTypes_js_1.oasExternalDocsData, externalDocs);
|
|
82
|
+
if (result.success) {
|
|
83
|
+
return result.output;
|
|
84
|
+
}
|
|
85
|
+
const reason = result.issues.map(({ message }) => message).join(', ');
|
|
86
|
+
context.logIssueNoKey({
|
|
87
|
+
stackTrail,
|
|
88
|
+
parent: externalDocs,
|
|
89
|
+
level: 'warning',
|
|
90
|
+
type: 'INVALID_EXTERNAL_DOCS',
|
|
91
|
+
message: `External docs object is invalid (${reason}); left out`
|
|
92
|
+
});
|
|
93
|
+
return undefined;
|
|
94
|
+
};
|
|
95
|
+
exports.toValidExternalDocs = toValidExternalDocs;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlainObject = void 0;
|
|
4
|
+
/** A non-null object that is not an array. */
|
|
5
|
+
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
exports.isPlainObject = isPlainObject;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
import type { OasIssueType } from '../context/generateTypes.js';
|
|
4
|
+
export type ToComponentEntriesArgs<Entry, Parsed> = {
|
|
5
|
+
entries: Record<string, Entry>;
|
|
6
|
+
/** Trail that ends in the bucket key, e.g. `components:headers`. */
|
|
7
|
+
stackTrail: StackTrail;
|
|
8
|
+
context: ParseContextType;
|
|
9
|
+
/** Issue type logged for an entry that fails to parse. */
|
|
10
|
+
type: OasIssueType;
|
|
11
|
+
/** Names the entry in the message, e.g. `Request body`. */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Parses one entry. An `undefined` result leaves the entry out. */
|
|
14
|
+
parse: (args: {
|
|
15
|
+
key: string;
|
|
16
|
+
entry: Entry;
|
|
17
|
+
stackTrail: StackTrail;
|
|
18
|
+
}) => Parsed | undefined;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse each entry of a `components` bucket inside its own `tryParseAt`
|
|
22
|
+
* boundary. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
23
|
+
*
|
|
24
|
+
* An entry that is not a plain object (`null`, an array, a string), or that
|
|
25
|
+
* throws while it parses, is dropped with one error of `type` at its
|
|
26
|
+
* location. Consumers reference it by name, so leaving it out silently would
|
|
27
|
+
* change what they render. The other entries are kept.
|
|
28
|
+
*/
|
|
29
|
+
export declare const toComponentEntries: <Entry, Parsed>({ entries, stackTrail, context, type, label, parse }: ToComponentEntriesArgs<Entry, Parsed>) => Record<string, Parsed>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toComponentEntries = void 0;
|
|
4
|
+
const tryParseAt_js_1 = require("../context/tryParseAt.js");
|
|
5
|
+
const isPlainObject_js_1 = require("./isPlainObject.js");
|
|
6
|
+
/**
|
|
7
|
+
* Parse each entry of a `components` bucket inside its own `tryParseAt`
|
|
8
|
+
* boundary. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
9
|
+
*
|
|
10
|
+
* An entry that is not a plain object (`null`, an array, a string), or that
|
|
11
|
+
* throws while it parses, is dropped with one error of `type` at its
|
|
12
|
+
* location. Consumers reference it by name, so leaving it out silently would
|
|
13
|
+
* change what they render. The other entries are kept.
|
|
14
|
+
*/
|
|
15
|
+
const toComponentEntries = ({ entries, stackTrail, context, type, label, parse }) => {
|
|
16
|
+
const parsedEntries = Object.entries(entries).flatMap(([key, entry]) => {
|
|
17
|
+
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
18
|
+
stackTrail,
|
|
19
|
+
key,
|
|
20
|
+
context,
|
|
21
|
+
type,
|
|
22
|
+
parent: entry,
|
|
23
|
+
fn: st => {
|
|
24
|
+
if (!(0, isPlainObject_js_1.isPlainObject)(entry)) {
|
|
25
|
+
throw new Error(`${label} must be an object, got ${toKind(entry)}`);
|
|
26
|
+
}
|
|
27
|
+
return parse({ key, entry, stackTrail: st });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return parsed === undefined ? [] : [[key, parsed]];
|
|
31
|
+
});
|
|
32
|
+
return Object.fromEntries(parsedEntries);
|
|
33
|
+
};
|
|
34
|
+
exports.toComponentEntries = toComponentEntries;
|
|
35
|
+
const toKind = (value) => value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
export type ToPresentInfoArgs<Info extends object> = {
|
|
4
|
+
info: Info | null | undefined;
|
|
5
|
+
/** Trail that ends in the `info` key. */
|
|
6
|
+
stackTrail: StackTrail;
|
|
7
|
+
context: ParseContextType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Check the document's `info` field before its fields are parsed. Shared by
|
|
11
|
+
* the 3.0, 3.1 and 3.2 parsers.
|
|
12
|
+
*
|
|
13
|
+
* Missing, `null` or not a plain object: logs one `MISSING_INFO` warning and
|
|
14
|
+
* returns `undefined`. The caller reads it as an empty title and version.
|
|
15
|
+
*/
|
|
16
|
+
export declare const toPresentInfo: <Info extends object>({ info, stackTrail, context }: ToPresentInfoArgs<Info>) => Info | undefined;
|
|
17
|
+
export type ToInfoStringArgs = {
|
|
18
|
+
value: unknown;
|
|
19
|
+
key: 'title' | 'version';
|
|
20
|
+
parent: unknown;
|
|
21
|
+
/** Trail that ends in the `info` key. */
|
|
22
|
+
stackTrail: StackTrail;
|
|
23
|
+
context: ParseContextType;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Read `info.title` or `info.version`. A value that is not a string (missing,
|
|
27
|
+
* or a YAML number such as `version: 1.0`) logs one `MISSING_INFO` warning
|
|
28
|
+
* and reads as `''`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const toInfoString: ({ value, key, parent, stackTrail, context }: ToInfoStringArgs) => string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toInfoString = exports.toPresentInfo = void 0;
|
|
4
|
+
const isPlainObject_js_1 = require("./isPlainObject.js");
|
|
5
|
+
/**
|
|
6
|
+
* Check the document's `info` field before its fields are parsed. Shared by
|
|
7
|
+
* the 3.0, 3.1 and 3.2 parsers.
|
|
8
|
+
*
|
|
9
|
+
* Missing, `null` or not a plain object: logs one `MISSING_INFO` warning and
|
|
10
|
+
* returns `undefined`. The caller reads it as an empty title and version.
|
|
11
|
+
*/
|
|
12
|
+
const toPresentInfo = ({ info, stackTrail, context }) => {
|
|
13
|
+
if (!(0, isPlainObject_js_1.isPlainObject)(info)) {
|
|
14
|
+
context.logIssueNoKey({
|
|
15
|
+
stackTrail,
|
|
16
|
+
parent: info,
|
|
17
|
+
level: 'warning',
|
|
18
|
+
type: 'MISSING_INFO',
|
|
19
|
+
message: 'Document has no info object; read as empty title and version'
|
|
20
|
+
});
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return info;
|
|
24
|
+
};
|
|
25
|
+
exports.toPresentInfo = toPresentInfo;
|
|
26
|
+
/**
|
|
27
|
+
* Read `info.title` or `info.version`. A value that is not a string (missing,
|
|
28
|
+
* or a YAML number such as `version: 1.0`) logs one `MISSING_INFO` warning
|
|
29
|
+
* and reads as `''`.
|
|
30
|
+
*/
|
|
31
|
+
const toInfoString = ({ value, key, parent, stackTrail, context }) => {
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
context.logIssue({
|
|
36
|
+
key,
|
|
37
|
+
stackTrail,
|
|
38
|
+
parent,
|
|
39
|
+
level: 'warning',
|
|
40
|
+
type: 'MISSING_INFO',
|
|
41
|
+
message: `Info has no string ${key}; read as ''`
|
|
42
|
+
});
|
|
43
|
+
return '';
|
|
44
|
+
};
|
|
45
|
+
exports.toInfoString = toInfoString;
|
|
@@ -35,7 +35,7 @@ const toComponentsV3 = ({ components, stackTrail, context }) => {
|
|
|
35
35
|
context
|
|
36
36
|
}),
|
|
37
37
|
requestBodies: stackTrail.trace('requestBodies', st => (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies, stackTrail: st, context })),
|
|
38
|
-
headers: stackTrail.trace('headers', st => (0, toHeadersV3_js_1.
|
|
38
|
+
headers: stackTrail.trace('headers', st => (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers, stackTrail: st, context })),
|
|
39
39
|
securitySchemes: stackTrail.trace('securitySchemes', st => (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes, stackTrail: st, context })),
|
|
40
40
|
links: stackTrail.trace('links', st => (0, toLinksV3_js_1.toLinksV3)({ links, stackTrail: st, context })),
|
|
41
41
|
extensionFields
|
|
@@ -4,7 +4,9 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
4
4
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
5
5
|
export type ToExternalDocsArgs = {
|
|
6
6
|
externalDocs: OpenAPIV3.ExternalDocumentationObject | undefined;
|
|
7
|
+
/** Trail that ends in the `externalDocs` key. */
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
12
|
+
export declare const toExternalDocs: ({ externalDocs, stackTrail, context }: ToExternalDocsArgs) => OasExternalDocs | undefined;
|
|
@@ -1,52 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.toExternalDocs = void 0;
|
|
37
4
|
const ExternalDocs_js_1 = require("../../../oas/externalDocs/ExternalDocs.js");
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const toExternalDocs = ({ externalDocs, stackTrail }) => {
|
|
41
|
-
if (
|
|
5
|
+
const descriptiveFields_js_1 = require("../../descriptiveFields.js");
|
|
6
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
7
|
+
const toExternalDocs = ({ externalDocs, stackTrail, context }) => {
|
|
8
|
+
if (externalDocs === undefined) {
|
|
42
9
|
return undefined;
|
|
43
10
|
}
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
const valid = (0, descriptiveFields_js_1.toValidExternalDocs)({ externalDocs, stackTrail, context });
|
|
12
|
+
if (!valid) {
|
|
13
|
+
return undefined;
|
|
46
14
|
}
|
|
47
15
|
return new ExternalDocs_js_1.OasExternalDocs({
|
|
48
|
-
url:
|
|
49
|
-
description:
|
|
16
|
+
url: valid.url,
|
|
17
|
+
description: valid.description
|
|
50
18
|
});
|
|
51
19
|
};
|
|
52
20
|
exports.toExternalDocs = toExternalDocs;
|