@skmtc/core 0.32.3 → 0.34.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 +2 -0
- package/esm/helpers/ResultsLog.d.ts +19 -181
- package/esm/helpers/ResultsLog.js +46 -205
- package/esm/parse/emptyParameter.d.ts +16 -0
- package/esm/parse/emptyParameter.js +19 -0
- package/esm/parse/toPresentResponses.d.ts +19 -0
- package/esm/parse/toPresentResponses.js +27 -0
- package/esm/parse/v3-0/parameter/toParameterV3.js +12 -3
- package/esm/parse/v3-0/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-0/response/toResponseV3.js +12 -1
- package/esm/parse/v3-1/parameter/toParameterV3.js +12 -3
- package/esm/parse/v3-1/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-1/response/toResponseV3.js +12 -1
- package/esm/parse/v3-2/parameter/toParameterV3.js +9 -0
- package/esm/parse/v3-2/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-2/response/toResponseV3.js +12 -1
- 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 +2 -0
- package/script/helpers/ResultsLog.d.ts +19 -181
- package/script/helpers/ResultsLog.js +46 -208
- package/script/parse/emptyParameter.d.ts +16 -0
- package/script/parse/emptyParameter.js +24 -0
- package/script/parse/toPresentResponses.d.ts +19 -0
- package/script/parse/toPresentResponses.js +31 -0
- package/script/parse/v3-0/parameter/toParameterV3.js +12 -3
- package/script/parse/v3-0/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-0/response/toResponseV3.js +13 -2
- package/script/parse/v3-1/parameter/toParameterV3.js +12 -3
- package/script/parse/v3-1/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-1/response/toResponseV3.js +13 -2
- package/script/parse/v3-2/parameter/toParameterV3.js +9 -0
- package/script/parse/v3-2/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-2/response/toResponseV3.js +13 -2
|
@@ -10,216 +10,69 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _ResultsLog_instances, _ResultsLog_results, _ResultsLog_incomingResultIsWorse;
|
|
13
|
-
import set from 'lodash-es/set.js';
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* Records one result per stack trail and builds the `manifest.results` tree.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* intelligent result prioritization, ensuring that more severe results (errors)
|
|
20
|
-
* take precedence over less severe ones (success, warnings) when multiple results
|
|
21
|
-
* exist for the same path.
|
|
16
|
+
* When several results are captured at the same trail, the most severe one
|
|
17
|
+
* wins (see `resultRankings`).
|
|
22
18
|
*
|
|
23
|
-
*
|
|
24
|
-
* identifiers to organize results in a meaningful hierarchical structure that
|
|
25
|
-
* reflects the execution flow of the generation process.
|
|
26
|
-
*
|
|
27
|
-
* ## Key Features
|
|
28
|
-
*
|
|
29
|
-
* - **Result Prioritization**: Automatically prioritizes more severe results
|
|
30
|
-
* - **Hierarchical Organization**: Organizes results by stack trail paths
|
|
31
|
-
* - **Tree Structure**: Converts flat result logs into nested tree structures
|
|
32
|
-
* - **Duplicate Handling**: Prevents less severe results from overwriting more severe ones
|
|
33
|
-
*
|
|
34
|
-
* @example Basic usage
|
|
19
|
+
* @example
|
|
35
20
|
* ```typescript
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* const resultsLog = new ResultsLog();
|
|
39
|
-
*
|
|
40
|
-
* // Capture results from different parts of generation
|
|
41
|
-
* resultsLog.capture('models:User', 'success');
|
|
42
|
-
* resultsLog.capture('models:Product', 'error');
|
|
43
|
-
* resultsLog.capture('types:Status', 'success');
|
|
44
|
-
*
|
|
45
|
-
* // Convert to hierarchical structure
|
|
46
|
-
* const tree = resultsLog.toTree();
|
|
47
|
-
* console.log(tree);
|
|
48
|
-
* // {
|
|
49
|
-
* // models: {
|
|
50
|
-
* // User: 'success',
|
|
51
|
-
* // Product: 'error'
|
|
52
|
-
* // },
|
|
53
|
-
* // types: {
|
|
54
|
-
* // Status: 'success'
|
|
55
|
-
* // }
|
|
56
|
-
* // }
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @example Result prioritization
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const resultsLog = new ResultsLog();
|
|
62
|
-
*
|
|
63
|
-
* // First capture a success
|
|
64
|
-
* resultsLog.capture('api:createUser', 'success');
|
|
65
|
-
*
|
|
66
|
-
* // Later encounter an error at the same path
|
|
67
|
-
* resultsLog.capture('api:createUser', 'error');
|
|
21
|
+
* const resultsLog = new ResultsLog()
|
|
68
22
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* console.log(tree.api.createUser); // 'error'
|
|
23
|
+
* resultsLog.capture(new StackTrail(['generate', '/pets', 'get']), 'success')
|
|
24
|
+
* resultsLog.capture(new StackTrail(['generate', '/pets/{id}:archive', 'post']), 'error')
|
|
72
25
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* console.log(resultsLog.toTree().api.createUser); // Still 'error'
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @example Complex nested paths
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const resultsLog = new ResultsLog();
|
|
81
|
-
*
|
|
82
|
-
* resultsLog.capture('generation:models:User:properties:name', 'success');
|
|
83
|
-
* resultsLog.capture('generation:models:User:properties:email', 'warning');
|
|
84
|
-
* resultsLog.capture('generation:models:Product:validation', 'error');
|
|
85
|
-
* resultsLog.capture('generation:operations:createUser', 'success');
|
|
86
|
-
*
|
|
87
|
-
* const tree = resultsLog.toTree();
|
|
88
|
-
* console.log(tree);
|
|
89
|
-
* // {
|
|
90
|
-
* // generation: {
|
|
91
|
-
* // models: {
|
|
92
|
-
* // User: {
|
|
93
|
-
* // properties: {
|
|
94
|
-
* // name: 'success',
|
|
95
|
-
* // email: 'warning'
|
|
96
|
-
* // }
|
|
97
|
-
* // },
|
|
98
|
-
* // Product: {
|
|
99
|
-
* // validation: 'error'
|
|
100
|
-
* // }
|
|
101
|
-
* // },
|
|
102
|
-
* // operations: {
|
|
103
|
-
* // createUser: 'success'
|
|
104
|
-
* // }
|
|
105
|
-
* // }
|
|
106
|
-
* // }
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* @example Integration with tracing
|
|
110
|
-
* ```typescript
|
|
111
|
-
* class TrackedGenerator {
|
|
112
|
-
* private resultsLog = new ResultsLog();
|
|
113
|
-
*
|
|
114
|
-
* generateModel(name: string, schema: OasSchema) {
|
|
115
|
-
* const stackPath = `models:${name}`;
|
|
116
|
-
*
|
|
117
|
-
* try {
|
|
118
|
-
* const model = this.processSchema(schema);
|
|
119
|
-
* this.resultsLog.capture(stackPath, 'success');
|
|
120
|
-
* return model;
|
|
121
|
-
* } catch (error) {
|
|
122
|
-
* this.resultsLog.capture(stackPath, 'error');
|
|
123
|
-
* throw error;
|
|
124
|
-
* }
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* generateOperation(operationId: string, operation: OasOperation) {
|
|
128
|
-
* const stackPath = `operations:${operationId}`;
|
|
129
|
-
*
|
|
130
|
-
* if (!this.supportsOperation(operation)) {
|
|
131
|
-
* this.resultsLog.capture(stackPath, 'notSupported');
|
|
132
|
-
* return null;
|
|
133
|
-
* }
|
|
134
|
-
*
|
|
135
|
-
* const result = this.processOperation(operation);
|
|
136
|
-
* this.resultsLog.capture(stackPath, 'success');
|
|
137
|
-
* return result;
|
|
138
|
-
* }
|
|
139
|
-
*
|
|
140
|
-
* getResults(): ResultsItem {
|
|
141
|
-
* return this.resultsLog.toTree();
|
|
142
|
-
* }
|
|
143
|
-
* }
|
|
26
|
+
* resultsLog.toTree()
|
|
27
|
+
* // { generate: { '/pets': { get: 'success' }, '/pets/{id}:archive': { post: 'error' } } }
|
|
144
28
|
* ```
|
|
145
29
|
*/
|
|
146
30
|
export class ResultsLog {
|
|
147
|
-
/**
|
|
148
|
-
* Creates a new ResultsLog instance.
|
|
149
|
-
*
|
|
150
|
-
* Initializes an empty results tracking system ready to capture
|
|
151
|
-
* generation outcomes from various parts of the pipeline.
|
|
152
|
-
*/
|
|
153
31
|
constructor() {
|
|
154
32
|
_ResultsLog_instances.add(this);
|
|
33
|
+
/**
|
|
34
|
+
* Keyed by `StackTrail.toString()`. The key is one-to-one with the frames,
|
|
35
|
+
* except that `[]` and `['']` both give `''`.
|
|
36
|
+
*/
|
|
155
37
|
_ResultsLog_results.set(this, void 0);
|
|
156
|
-
__classPrivateFieldSet(this, _ResultsLog_results,
|
|
38
|
+
__classPrivateFieldSet(this, _ResultsLog_results, new Map(), "f");
|
|
157
39
|
}
|
|
158
40
|
/**
|
|
159
|
-
* Captures
|
|
160
|
-
*
|
|
161
|
-
* This method records the outcome of a generation operation, using intelligent
|
|
162
|
-
* prioritization to ensure that more severe results take precedence over less
|
|
163
|
-
* severe ones. For example, an error result will not be overwritten by a
|
|
164
|
-
* success result, but a success can be overwritten by an error.
|
|
165
|
-
*
|
|
166
|
-
* @param stackTrail - Colon-separated path identifying the operation location
|
|
167
|
-
* @param result - The result type to capture (error, warning, success, etc.)
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* const resultsLog = new ResultsLog();
|
|
41
|
+
* Captures `result` at `stackTrail`, unless a more severe result is
|
|
42
|
+
* already recorded there.
|
|
172
43
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* resultsLog.capture('models:User:validation', 'warning');
|
|
176
|
-
* resultsLog.capture('operations:createUser', 'error');
|
|
177
|
-
* ```
|
|
44
|
+
* Stores a copy of the frames: `StackTrail.trace` pops the live array
|
|
45
|
+
* after its callback returns.
|
|
178
46
|
*/
|
|
179
47
|
capture(stackTrail, result) {
|
|
180
|
-
|
|
181
|
-
|
|
48
|
+
const key = stackTrail.toString();
|
|
49
|
+
if (__classPrivateFieldGet(this, _ResultsLog_instances, "m", _ResultsLog_incomingResultIsWorse).call(this, __classPrivateFieldGet(this, _ResultsLog_results, "f").get(key)?.result, result)) {
|
|
50
|
+
__classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames: [...stackTrail.stackTrail], result });
|
|
182
51
|
}
|
|
183
52
|
}
|
|
184
53
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* operations. This makes it easier to understand and process results in
|
|
190
|
-
* a structured way.
|
|
191
|
-
*
|
|
192
|
-
* @returns Nested object structure representing the results hierarchy
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* const resultsLog = new ResultsLog();
|
|
197
|
-
* resultsLog.capture('api:models:User', 'success');
|
|
198
|
-
* resultsLog.capture('api:operations:getUser', 'error');
|
|
199
|
-
* resultsLog.capture('types:Status', 'success');
|
|
200
|
-
*
|
|
201
|
-
* const tree = resultsLog.toTree();
|
|
202
|
-
* console.log(tree);
|
|
203
|
-
* // {
|
|
204
|
-
* // api: {
|
|
205
|
-
* // models: {
|
|
206
|
-
* // User: 'success'
|
|
207
|
-
* // },
|
|
208
|
-
* // operations: {
|
|
209
|
-
* // getUser: 'error'
|
|
210
|
-
* // }
|
|
211
|
-
* // },
|
|
212
|
-
* // types: {
|
|
213
|
-
* // Status: 'success'
|
|
214
|
-
* // }
|
|
215
|
-
* // }
|
|
216
|
-
* ```
|
|
54
|
+
* Nests the captured results by their frames, one object level per frame.
|
|
55
|
+
* Frames are used as own-property keys verbatim, so a frame such as
|
|
56
|
+
* `constructor`, `toString` or `0` is a key like any other. A result
|
|
57
|
+
* captured at the empty trail has no key and is left out.
|
|
217
58
|
*/
|
|
218
59
|
toTree() {
|
|
219
60
|
const tree = {};
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
61
|
+
__classPrivateFieldGet(this, _ResultsLog_results, "f").forEach(({ frames, result }) => {
|
|
62
|
+
const leafFrame = frames.at(-1);
|
|
63
|
+
if (leafFrame === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const parent = frames.slice(0, -1).reduce((node, frame) => {
|
|
67
|
+
const existing = Object.hasOwn(node, frame) ? node[frame] : undefined;
|
|
68
|
+
if (typeof existing === 'object' && existing !== null && !Array.isArray(existing)) {
|
|
69
|
+
return existing;
|
|
70
|
+
}
|
|
71
|
+
const child = {};
|
|
72
|
+
defineOwn(node, frame, child);
|
|
73
|
+
return child;
|
|
74
|
+
}, tree);
|
|
75
|
+
defineOwn(parent, leafFrame, result);
|
|
223
76
|
});
|
|
224
77
|
return tree;
|
|
225
78
|
}
|
|
@@ -230,25 +83,13 @@ _ResultsLog_results = new WeakMap(), _ResultsLog_instances = new WeakSet(), _Res
|
|
|
230
83
|
}
|
|
231
84
|
return resultRankings[current] < resultRankings[incoming];
|
|
232
85
|
};
|
|
86
|
+
/** Writes an own, enumerable property, even for keys such as `__proto__`. */
|
|
87
|
+
const defineOwn = (node, key, value) => {
|
|
88
|
+
Object.defineProperty(node, key, { value, enumerable: true, writable: true, configurable: true });
|
|
89
|
+
};
|
|
233
90
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* This mapping defines the severity hierarchy used by the ResultsLog to determine
|
|
237
|
-
* which results should take precedence when multiple results are captured for the
|
|
238
|
-
* same path. Higher numbers indicate higher severity/priority.
|
|
239
|
-
*
|
|
240
|
-
* The ranking system ensures that critical issues (errors) are never masked by
|
|
241
|
-
* less important results (success), while still allowing for proper escalation
|
|
242
|
-
* when more severe conditions are encountered.
|
|
243
|
-
*
|
|
244
|
-
* @example Ranking hierarchy (high to low priority)
|
|
245
|
-
* ```
|
|
246
|
-
* error (50) - Critical failures that prevent generation
|
|
247
|
-
* warning (40) - Issues that allow generation but need attention
|
|
248
|
-
* success (30) - Normal successful completion
|
|
249
|
-
* skipped (20) - Operations that were intentionally bypassed
|
|
250
|
-
* notSupported (10) - Features not yet implemented
|
|
251
|
-
* ```
|
|
91
|
+
* Severity of each result type. A higher number replaces a lower one
|
|
92
|
+
* captured at the same trail.
|
|
252
93
|
*/
|
|
253
94
|
const resultRankings = {
|
|
254
95
|
error: 50,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
5
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
6
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isEmptyParameter: (parameter: unknown) => boolean;
|
|
9
|
+
export type LogEmptyParameterArgs = {
|
|
10
|
+
parameter: unknown;
|
|
11
|
+
/** Trail that ends in the entry's index or name. */
|
|
12
|
+
stackTrail: StackTrail;
|
|
13
|
+
context: ParseContextType;
|
|
14
|
+
};
|
|
15
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
16
|
+
export declare const logEmptyParameter: ({ parameter, stackTrail, context }: LogEmptyParameterArgs) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
3
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
4
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
5
|
+
*/
|
|
6
|
+
export const isEmptyParameter = (parameter) => parameter === null ||
|
|
7
|
+
(typeof parameter === 'object' &&
|
|
8
|
+
!Array.isArray(parameter) &&
|
|
9
|
+
Object.keys(parameter).length === 0);
|
|
10
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
11
|
+
export const logEmptyParameter = ({ parameter, stackTrail, context }) => {
|
|
12
|
+
context.logIssueNoKey({
|
|
13
|
+
stackTrail,
|
|
14
|
+
parent: parameter,
|
|
15
|
+
level: 'warning',
|
|
16
|
+
type: 'EMPTY_PARAMETER',
|
|
17
|
+
message: 'Empty parameter object; skipped'
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
export type ToPresentResponsesArgs<Responses extends object> = {
|
|
4
|
+
responses: Responses | null | undefined;
|
|
5
|
+
/** Trail that ends in the `responses` key. */
|
|
6
|
+
stackTrail: StackTrail;
|
|
7
|
+
context: ParseContextType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
11
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
12
|
+
*
|
|
13
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
14
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
15
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
16
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
17
|
+
* - Otherwise: returns `responses`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toPresentResponses: <Responses extends object>({ responses, stackTrail, context }: ToPresentResponsesArgs<Responses>) => Responses | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
3
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
4
|
+
*
|
|
5
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
6
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
7
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
8
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
9
|
+
* - Otherwise: returns `responses`.
|
|
10
|
+
*/
|
|
11
|
+
export const toPresentResponses = ({ responses, stackTrail, context }) => {
|
|
12
|
+
if (responses === undefined || responses === null) {
|
|
13
|
+
context.logIssueNoKey({
|
|
14
|
+
stackTrail,
|
|
15
|
+
parent: undefined,
|
|
16
|
+
level: 'warning',
|
|
17
|
+
type: 'MISSING_RESPONSES',
|
|
18
|
+
message: 'Operation has no responses; read as no documented responses'
|
|
19
|
+
});
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (typeof responses !== 'object' || Array.isArray(responses)) {
|
|
23
|
+
const actual = Array.isArray(responses) ? 'an array' : typeof responses;
|
|
24
|
+
throw new Error(`"responses" must be an object of status codes, got ${actual}`);
|
|
25
|
+
}
|
|
26
|
+
return responses;
|
|
27
|
+
};
|
|
@@ -7,6 +7,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
7
7
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
10
11
|
const parameterLocation = v.enum({
|
|
11
12
|
query: 'query',
|
|
12
13
|
header: 'header',
|
|
@@ -26,14 +27,22 @@ export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
26
27
|
if (!parameters) {
|
|
27
28
|
return undefined;
|
|
28
29
|
}
|
|
29
|
-
return parameters.
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
|
|
31
|
+
if (isEmptyParameter(parameter)) {
|
|
32
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
+
}));
|
|
32
37
|
};
|
|
33
38
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
34
39
|
const output = {};
|
|
35
40
|
const entries = Object.entries(parameters);
|
|
36
41
|
for (const [key, parameter] of entries) {
|
|
42
|
+
if (isEmptyParameter(parameter)) {
|
|
43
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
37
46
|
const parsed = tryParseAt({
|
|
38
47
|
stackTrail,
|
|
39
48
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
|
@@ -7,6 +7,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
7
7
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
10
11
|
const parameterLocation = v.enum({
|
|
11
12
|
query: 'query',
|
|
12
13
|
header: 'header',
|
|
@@ -26,14 +27,22 @@ export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
26
27
|
if (!parameters) {
|
|
27
28
|
return undefined;
|
|
28
29
|
}
|
|
29
|
-
return parameters.
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
|
|
31
|
+
if (isEmptyParameter(parameter)) {
|
|
32
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
+
}));
|
|
32
37
|
};
|
|
33
38
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
34
39
|
const output = {};
|
|
35
40
|
const entries = Object.entries(parameters);
|
|
36
41
|
for (const [key, parameter] of entries) {
|
|
42
|
+
if (isEmptyParameter(parameter)) {
|
|
43
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
37
46
|
const parsed = tryParseAt({
|
|
38
47
|
stackTrail,
|
|
39
48
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
|
@@ -8,11 +8,16 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
8
8
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
9
9
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
10
10
|
import * as v from 'valibot';
|
|
11
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
11
12
|
export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
12
13
|
if (!parameters) {
|
|
13
14
|
return undefined;
|
|
14
15
|
}
|
|
15
16
|
return parameters.flatMap((parameter, index) => {
|
|
17
|
+
if (isEmptyParameter(parameter)) {
|
|
18
|
+
stackTrail.trace(`${index}`, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
16
21
|
const querystringIssue = toQuerystringIssue(parameter);
|
|
17
22
|
if (querystringIssue) {
|
|
18
23
|
context.logIssue({
|
|
@@ -49,6 +54,10 @@ export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
|
49
54
|
const output = {};
|
|
50
55
|
const entries = Object.entries(parameters);
|
|
51
56
|
for (const [key, parameter] of entries) {
|
|
57
|
+
if (isEmptyParameter(parameter)) {
|
|
58
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
52
61
|
const parsed = tryParseAt({
|
|
53
62
|
stackTrail,
|
|
54
63
|
key,
|
|
@@ -10,10 +10,14 @@ export type ResponseObjectV32 = OpenAPIV3.ResponseObject & {
|
|
|
10
10
|
/** A 3.2 Responses Object: status code to a 3.2 Response Object or a reference. */
|
|
11
11
|
export type ResponsesObjectV32 = Record<string, OpenAPIV3.ReferenceObject | ResponseObjectV32>;
|
|
12
12
|
export type ToResponsesV3Args = {
|
|
13
|
-
responses
|
|
13
|
+
responses?: ResponsesObjectV32 | null;
|
|
14
14
|
stackTrail: StackTrail;
|
|
15
15
|
context: ParseContextType;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
19
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
20
|
+
*/
|
|
17
21
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
18
22
|
export type ToOptionalResponsesV3Args = {
|
|
19
23
|
responses: ResponsesObjectV32 | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
package/package.json
CHANGED
|
@@ -305,31 +305,18 @@ export declare class CoreContext {
|
|
|
305
305
|
parseIssues: ParseIssue[];
|
|
306
306
|
};
|
|
307
307
|
/**
|
|
308
|
-
* Captures a result at
|
|
309
|
-
*
|
|
310
|
-
* This method records processing results (success, warning, error, etc.) at the
|
|
311
|
-
* current location in the document traversal stack. Results are associated with
|
|
312
|
-
* the current stack trail position, enabling detailed error reporting and
|
|
313
|
-
* debugging of OpenAPI processing issues.
|
|
308
|
+
* Captures a result at `stackTrail`. Each frame of the trail becomes one
|
|
309
|
+
* level of the `manifest.results` tree.
|
|
314
310
|
*
|
|
315
311
|
* @param result - The type of result to capture (success, warning, error, etc.)
|
|
312
|
+
* @param stackTrail - The trail the result belongs to
|
|
316
313
|
*
|
|
317
|
-
* @example
|
|
318
|
-
* ```typescript
|
|
319
|
-
* context.captureCurrentResult('warning');
|
|
320
|
-
* // Result captured at current stack position like: "components.schemas.User.properties.email"
|
|
321
|
-
* ```
|
|
322
|
-
*
|
|
323
|
-
* @example Usage during schema processing
|
|
314
|
+
* @example
|
|
324
315
|
* ```typescript
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* } catch (error) {
|
|
330
|
-
* context.captureCurrentResult('error');
|
|
331
|
-
* }
|
|
332
|
-
* });
|
|
316
|
+
* stackTrail.trace(['/pets', 'get'], opTrail => {
|
|
317
|
+
* context.captureCurrentResult('success', opTrail)
|
|
318
|
+
* })
|
|
319
|
+
* // manifest.results: { …, '/pets': { get: 'success' } }
|
|
333
320
|
* ```
|
|
334
321
|
*/
|
|
335
322
|
captureCurrentResult(result: ResultType, stackTrail: StackTrail): void;
|