@skmtc/core 0.35.0 → 0.35.2
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/StackTrail.js +3 -13
- package/esm/context/documentTrail.d.ts +17 -0
- package/esm/context/documentTrail.js +28 -0
- package/esm/parse/pathParameters.d.ts +57 -0
- package/esm/parse/pathParameters.js +138 -0
- package/esm/parse/v3-0/_merge-all-of/merge-bounds.d.ts +7 -0
- package/esm/parse/v3-0/_merge-all-of/merge-bounds.js +46 -0
- package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
- package/esm/parse/v3-1/_merge-all-of/decompose-union.js +3 -1
- package/esm/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
- package/esm/parse/v3-1/_merge-all-of/merge-bounds.js +57 -0
- package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +65 -7
- package/esm/parse/v3-1/_merge-all-of/merge.js +7 -3
- package/esm/parse/v3-1/array/toArray.js +4 -15
- package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-1/schema/normalize-schema-shape.js +10 -8
- package/esm/parse/v3-1/schema/toSchemasV3.js +7 -1
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
- package/esm/parse/v3-2/_merge-all-of/decompose-union.js +3 -1
- package/esm/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
- package/esm/parse/v3-2/_merge-all-of/merge-bounds.js +57 -0
- package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +65 -7
- package/esm/parse/v3-2/_merge-all-of/merge.js +7 -3
- package/esm/parse/v3-2/array/toArray.js +4 -15
- package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
- package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
- package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
- package/esm/parse/v3-2/schema/normalize-schema-shape.js +10 -8
- package/esm/parse/v3-2/schema/toSchemasV3.js +7 -1
- package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
- package/package.json +1 -1
- package/script/context/StackTrail.js +3 -13
- package/script/context/documentTrail.d.ts +17 -0
- package/script/context/documentTrail.js +34 -0
- package/script/parse/pathParameters.d.ts +57 -0
- package/script/parse/pathParameters.js +144 -0
- package/script/parse/v3-0/_merge-all-of/merge-bounds.d.ts +7 -0
- package/script/parse/v3-0/_merge-all-of/merge-bounds.js +50 -0
- package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
- package/script/parse/v3-1/_merge-all-of/decompose-union.js +5 -2
- package/script/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
- package/script/parse/v3-1/_merge-all-of/merge-bounds.js +66 -0
- package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
- package/script/parse/v3-1/_merge-all-of/merge-union.js +66 -7
- package/script/parse/v3-1/_merge-all-of/merge.js +6 -2
- package/script/parse/v3-1/array/toArray.js +4 -15
- package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-1/schema/normalize-schema-shape.js +10 -8
- package/script/parse/v3-1/schema/toSchemasV3.js +6 -0
- package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
- package/script/parse/v3-2/_merge-all-of/decompose-union.js +5 -2
- package/script/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
- package/script/parse/v3-2/_merge-all-of/merge-bounds.js +66 -0
- package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
- package/script/parse/v3-2/_merge-all-of/merge-union.js +66 -7
- package/script/parse/v3-2/_merge-all-of/merge.js +6 -2
- package/script/parse/v3-2/array/toArray.js +4 -15
- package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
- package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
- package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
- package/script/parse/v3-2/schema/normalize-schema-shape.js +10 -8
- package/script/parse/v3-2/schema/toSchemasV3.js +6 -0
- package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
|
@@ -13,6 +13,7 @@ var _StackTrail_stack;
|
|
|
13
13
|
import "../_dnt.polyfills.js";
|
|
14
14
|
import { componentsKeys } from '../oas/components/Components.js';
|
|
15
15
|
import { toJsonPointer } from '../types/JsonPointer.js';
|
|
16
|
+
import { toDocumentFrames, toTrailString } from './documentTrail.js';
|
|
16
17
|
export class StackTrail {
|
|
17
18
|
constructor(stack = []) {
|
|
18
19
|
/** Internal stack of traversal frames */
|
|
@@ -211,15 +212,7 @@ export class StackTrail {
|
|
|
211
212
|
* ```
|
|
212
213
|
*/
|
|
213
214
|
toSchemaPointer() {
|
|
214
|
-
|
|
215
|
-
// `post-pass` trace). The operational phase always sits before any
|
|
216
|
-
// document key, so the FIRST match is the boundary — a document key
|
|
217
|
-
// that happens to share a phase name (e.g. a schema literally named
|
|
218
|
-
// `parse`) appears later and is unaffected.
|
|
219
|
-
const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
|
|
220
|
-
const phaseIndex = __classPrivateFieldGet(this, _StackTrail_stack, "f").findIndex(frame => phaseFrames.has(frame));
|
|
221
|
-
const documentFrames = phaseIndex === -1 ? __classPrivateFieldGet(this, _StackTrail_stack, "f") : __classPrivateFieldGet(this, _StackTrail_stack, "f").slice(phaseIndex + 1);
|
|
222
|
-
return toJsonPointer(documentFrames);
|
|
215
|
+
return toJsonPointer(toDocumentFrames(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
|
|
223
216
|
}
|
|
224
217
|
toStackRef() {
|
|
225
218
|
const [first, second, third] = this.stackTrail;
|
|
@@ -305,9 +298,7 @@ export class StackTrail {
|
|
|
305
298
|
* ```
|
|
306
299
|
*/
|
|
307
300
|
toString() {
|
|
308
|
-
return __classPrivateFieldGet(this, _StackTrail_stack, "f")
|
|
309
|
-
.map(frame => frame.replace(/[%:]/g, character => escapes[character]))
|
|
310
|
-
.join(':');
|
|
301
|
+
return toTrailString(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
|
|
311
302
|
}
|
|
312
303
|
/**
|
|
313
304
|
* Reads a string written by {@link StackTrail.toString} back into a trail.
|
|
@@ -330,5 +321,4 @@ export class StackTrail {
|
|
|
330
321
|
}
|
|
331
322
|
}
|
|
332
323
|
_StackTrail_stack = new WeakMap();
|
|
333
|
-
const escapes = { '%': '%25', ':': '%3A' };
|
|
334
324
|
const decodes = { '25': '%', '3A': ':' };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
|
|
2
|
+
export declare const toTrailString: (frames: string[]) => string;
|
|
3
|
+
/**
|
|
4
|
+
* The frames of a trail that address the input document: everything after
|
|
5
|
+
* the first phase frame, or every frame when there is no phase frame.
|
|
6
|
+
*/
|
|
7
|
+
export declare const toDocumentFrames: (frames: string[]) => string[];
|
|
8
|
+
/**
|
|
9
|
+
* The document-relative trail in `StackTrail.toString` form.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
|
|
14
|
+
* // 'paths:/pets:parameters:0'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const toDocumentString: (frames: string[]) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const escapes = { '%': '%25', ':': '%3A' };
|
|
2
|
+
// Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
|
|
3
|
+
// `post-pass` trace).
|
|
4
|
+
const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
|
|
5
|
+
/** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
|
|
6
|
+
export const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
|
|
7
|
+
/**
|
|
8
|
+
* The frames of a trail that address the input document: everything after
|
|
9
|
+
* the first phase frame, or every frame when there is no phase frame.
|
|
10
|
+
*/
|
|
11
|
+
export const toDocumentFrames = (frames) => {
|
|
12
|
+
// The operational phase always sits before any document key, so the
|
|
13
|
+
// FIRST match is the boundary — a document key that happens to share a
|
|
14
|
+
// phase name (e.g. a schema literally named `parse`) appears later and
|
|
15
|
+
// is unaffected.
|
|
16
|
+
const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
|
|
17
|
+
return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The document-relative trail in `StackTrail.toString` form.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
|
|
25
|
+
* // 'paths:/pets:parameters:0'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const toDocumentString = (frames) => toTrailString(toDocumentFrames(frames));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
|
|
5
|
+
* is read as no parameters with an `EMPTY_PARAMETER` warning at the
|
|
6
|
+
* field. Any other value that is not an array throws.
|
|
7
|
+
*/
|
|
8
|
+
export declare const toParameterEntries: <Entry>({ parameters, stackTrail, context }: {
|
|
9
|
+
parameters: Entry[] | undefined;
|
|
10
|
+
/** Trail that ends in `parameters`. */
|
|
11
|
+
stackTrail: StackTrail;
|
|
12
|
+
context: ParseContextType;
|
|
13
|
+
}) => Entry[] | undefined;
|
|
14
|
+
/** A path-level parameter entry, or the whole field, that failed to parse. */
|
|
15
|
+
export type BrokenPathParameter = {
|
|
16
|
+
/** Document-relative trail of the entry, or of the `parameters` field when it is not an array. */
|
|
17
|
+
location: string;
|
|
18
|
+
/** Set only when the raw entry has string `name` and `in`. */
|
|
19
|
+
name?: string;
|
|
20
|
+
in?: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
export type PathParameterList<Parameter> = {
|
|
24
|
+
parameters: Parameter[] | undefined;
|
|
25
|
+
broken: BrokenPathParameter[];
|
|
26
|
+
};
|
|
27
|
+
export type ToPathParameterListArgs<Entry, Parameter> = {
|
|
28
|
+
parameters: Entry[] | undefined;
|
|
29
|
+
/** Trail that ends in `parameters`. */
|
|
30
|
+
stackTrail: StackTrail;
|
|
31
|
+
context: ParseContextType;
|
|
32
|
+
/** The tree's parser for one list entry, as used by `toParameterListV3`. */
|
|
33
|
+
toEntry: (args: {
|
|
34
|
+
parameter: Entry;
|
|
35
|
+
index: number;
|
|
36
|
+
}) => Parameter[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Parses a path item's `parameters` without letting a throw escape. Each
|
|
40
|
+
* entry that fails logs one `INVALID_PARAMETER` error at its index and is
|
|
41
|
+
* returned in `broken`; a field that is not an array logs one at the field.
|
|
42
|
+
* The caller decides per operation which broken entries apply.
|
|
43
|
+
*/
|
|
44
|
+
export declare const toPathParameterList: <Entry, Parameter>({ parameters, stackTrail, context, toEntry }: ToPathParameterListArgs<Entry, Parameter>) => PathParameterList<Parameter>;
|
|
45
|
+
/**
|
|
46
|
+
* True when a broken path-level parameter applies to the operation. Logs
|
|
47
|
+
* one `INVALID_OPERATION` error at the operation that names the first
|
|
48
|
+
* such entry.
|
|
49
|
+
*/
|
|
50
|
+
export declare const isDroppedByPathParameter: ({ brokenParameters, operation, stackTrail, context }: {
|
|
51
|
+
brokenParameters: BrokenPathParameter[];
|
|
52
|
+
/** The raw operation object. */
|
|
53
|
+
operation: unknown;
|
|
54
|
+
/** Trail that ends in the operation's method. */
|
|
55
|
+
stackTrail: StackTrail;
|
|
56
|
+
context: ParseContextType;
|
|
57
|
+
}) => boolean;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { isEmptyParameter } from './emptyParameter.js';
|
|
2
|
+
import { toDocumentString } from '../context/documentTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
|
|
5
|
+
* is read as no parameters with an `EMPTY_PARAMETER` warning at the
|
|
6
|
+
* field. Any other value that is not an array throws.
|
|
7
|
+
*/
|
|
8
|
+
export const toParameterEntries = ({ parameters, stackTrail, context }) => {
|
|
9
|
+
if (parameters === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(parameters)) {
|
|
13
|
+
return parameters;
|
|
14
|
+
}
|
|
15
|
+
if (isEmptyParameter(parameters)) {
|
|
16
|
+
context.logIssueNoKey({
|
|
17
|
+
stackTrail,
|
|
18
|
+
parent: parameters,
|
|
19
|
+
level: 'warning',
|
|
20
|
+
type: 'EMPTY_PARAMETER',
|
|
21
|
+
message: 'Empty parameters field; read as no parameters'
|
|
22
|
+
});
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Expected parameters to be an array but received ${typeof parameters}`);
|
|
26
|
+
};
|
|
27
|
+
const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
28
|
+
const toNameAndIn = (parameter) => {
|
|
29
|
+
if (typeof parameter === 'object' &&
|
|
30
|
+
parameter !== null &&
|
|
31
|
+
'name' in parameter &&
|
|
32
|
+
'in' in parameter &&
|
|
33
|
+
typeof parameter.name === 'string' &&
|
|
34
|
+
typeof parameter.in === 'string') {
|
|
35
|
+
return { name: parameter.name, in: parameter.in };
|
|
36
|
+
}
|
|
37
|
+
return {};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Parses a path item's `parameters` without letting a throw escape. Each
|
|
41
|
+
* entry that fails logs one `INVALID_PARAMETER` error at its index and is
|
|
42
|
+
* returned in `broken`; a field that is not an array logs one at the field.
|
|
43
|
+
* The caller decides per operation which broken entries apply.
|
|
44
|
+
*/
|
|
45
|
+
export const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
|
|
46
|
+
const logBroken = (st, parent, error) => {
|
|
47
|
+
const normalized = toError(error);
|
|
48
|
+
context.logIssueNoKey({
|
|
49
|
+
level: 'error',
|
|
50
|
+
stackTrail: st,
|
|
51
|
+
parent,
|
|
52
|
+
message: normalized.message,
|
|
53
|
+
cause: normalized,
|
|
54
|
+
type: 'INVALID_PARAMETER'
|
|
55
|
+
});
|
|
56
|
+
return { location: toDocumentString(st.stackTrail), message: normalized.message };
|
|
57
|
+
};
|
|
58
|
+
const readEntries = () => {
|
|
59
|
+
try {
|
|
60
|
+
return { entries: toParameterEntries({ parameters, stackTrail, context }) };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// A field that is not an array cannot be matched to an override.
|
|
64
|
+
return { broken: logBroken(stackTrail, parameters, error) };
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const read = readEntries();
|
|
68
|
+
if ('broken' in read) {
|
|
69
|
+
return { parameters: undefined, broken: [read.broken] };
|
|
70
|
+
}
|
|
71
|
+
if (read.entries === undefined) {
|
|
72
|
+
return { parameters: undefined, broken: [] };
|
|
73
|
+
}
|
|
74
|
+
const results = read.entries.map((parameter, index) => {
|
|
75
|
+
try {
|
|
76
|
+
return { parsed: toEntry({ parameter, index }), broken: [] };
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
parsed: [],
|
|
81
|
+
broken: [
|
|
82
|
+
{
|
|
83
|
+
...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
|
|
84
|
+
...toNameAndIn(parameter)
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
parameters: results.flatMap(({ parsed }) => parsed),
|
|
92
|
+
broken: results.flatMap(({ broken }) => broken)
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The first broken path-level parameter that applies to an operation. An
|
|
97
|
+
* entry applies unless it has a readable `name` and `in` and the
|
|
98
|
+
* operation's inline `parameters` hold the same pair, which overrides it.
|
|
99
|
+
* A `$ref` operation parameter cannot be resolved during parse, so it
|
|
100
|
+
* overrides nothing.
|
|
101
|
+
*/
|
|
102
|
+
const toApplyingBrokenParameter = ({ broken, operation }) => {
|
|
103
|
+
if (broken.length === 0) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const operationParameters = typeof operation === 'object' &&
|
|
107
|
+
operation !== null &&
|
|
108
|
+
'parameters' in operation &&
|
|
109
|
+
Array.isArray(operation.parameters)
|
|
110
|
+
? operation.parameters
|
|
111
|
+
: [];
|
|
112
|
+
const overrides = new Set(operationParameters.flatMap((parameter) => {
|
|
113
|
+
const { name, in: parameterIn } = toNameAndIn(parameter);
|
|
114
|
+
return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
|
|
115
|
+
}));
|
|
116
|
+
return broken.find(entry => entry.name === undefined ||
|
|
117
|
+
entry.in === undefined ||
|
|
118
|
+
!overrides.has(`${entry.in}:${entry.name}`));
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* True when a broken path-level parameter applies to the operation. Logs
|
|
122
|
+
* one `INVALID_OPERATION` error at the operation that names the first
|
|
123
|
+
* such entry.
|
|
124
|
+
*/
|
|
125
|
+
export const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
|
|
126
|
+
const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
|
|
127
|
+
if (!broken) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
context.logIssueNoKey({
|
|
131
|
+
parent: operation,
|
|
132
|
+
level: 'error',
|
|
133
|
+
message: `Path-level parameter ${broken.location} failed to parse: ${broken.message}`,
|
|
134
|
+
stackTrail,
|
|
135
|
+
type: 'INVALID_OPERATION'
|
|
136
|
+
});
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SchemaObject } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
|
|
4
|
+
* of `first` and `second` onto `result`. Members are in the normalized form,
|
|
5
|
+
* where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mergeBounds: (result: SchemaObject, first: SchemaObject, second: SchemaObject) => void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pick the tighter of two bounds. The tighter bound keeps its own
|
|
3
|
+
* exclusivity; when both bounds are equal, exclusive wins.
|
|
4
|
+
*/
|
|
5
|
+
const toTighterBound = (first, second, isTighter) => {
|
|
6
|
+
if (first === undefined || second === undefined) {
|
|
7
|
+
return first ?? second;
|
|
8
|
+
}
|
|
9
|
+
if (first.value === second.value) {
|
|
10
|
+
return { value: first.value, exclusive: first.exclusive || second.exclusive };
|
|
11
|
+
}
|
|
12
|
+
return isTighter(first.value, second.value) ? first : second;
|
|
13
|
+
};
|
|
14
|
+
const toMinimum = (schema) => schema.minimum === undefined
|
|
15
|
+
? undefined
|
|
16
|
+
: { value: schema.minimum, exclusive: schema.exclusiveMinimum === true };
|
|
17
|
+
const toMaximum = (schema) => schema.maximum === undefined
|
|
18
|
+
? undefined
|
|
19
|
+
: { value: schema.maximum, exclusive: schema.exclusiveMaximum === true };
|
|
20
|
+
/**
|
|
21
|
+
* Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
|
|
22
|
+
* of `first` and `second` onto `result`. Members are in the normalized form,
|
|
23
|
+
* where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
|
|
24
|
+
*/
|
|
25
|
+
export const mergeBounds = (result, first, second) => {
|
|
26
|
+
const minimum = toTighterBound(toMinimum(first), toMinimum(second), (a, b) => a > b);
|
|
27
|
+
const maximum = toTighterBound(toMaximum(first), toMaximum(second), (a, b) => a < b);
|
|
28
|
+
if (minimum !== undefined) {
|
|
29
|
+
result.minimum = minimum.value;
|
|
30
|
+
if (minimum.exclusive) {
|
|
31
|
+
result.exclusiveMinimum = true;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
delete result.exclusiveMinimum;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (maximum !== undefined) {
|
|
38
|
+
result.maximum = maximum.value;
|
|
39
|
+
if (maximum.exclusive) {
|
|
40
|
+
result.exclusiveMaximum = true;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
delete result.exclusiveMaximum;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { genericMerge } from './generic-merge.js';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
4
|
+
import { mergeBounds } from './merge-bounds.js';
|
|
4
5
|
export function mergeIntegerConstraints(first, second, getRef) {
|
|
5
6
|
checkTypeConflicts(first, second);
|
|
6
7
|
// First merge enum values if present
|
|
7
8
|
const result = genericMerge(first, second, getRef, v.number());
|
|
8
9
|
// Then merge other constraints
|
|
9
10
|
result.type = 'integer';
|
|
10
|
-
|
|
11
|
-
if (first.minimum !== undefined || second.minimum !== undefined) {
|
|
12
|
-
const minA = first.minimum ?? -Infinity;
|
|
13
|
-
const minB = second.minimum ?? -Infinity;
|
|
14
|
-
result.minimum = Math.max(minA, minB);
|
|
15
|
-
// If either minimum is exclusive, the result is exclusive
|
|
16
|
-
if (first.exclusiveMinimum || second.exclusiveMinimum) {
|
|
17
|
-
result.exclusiveMinimum = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Merge maximum and exclusiveMaximum
|
|
21
|
-
if (first.maximum !== undefined || second.maximum !== undefined) {
|
|
22
|
-
const maxA = first.maximum ?? Infinity;
|
|
23
|
-
const maxB = second.maximum ?? Infinity;
|
|
24
|
-
result.maximum = Math.min(maxA, maxB);
|
|
25
|
-
// If either maximum is exclusive, the result is exclusive
|
|
26
|
-
if (first.exclusiveMaximum || second.exclusiveMaximum) {
|
|
27
|
-
result.exclusiveMaximum = true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
11
|
+
mergeBounds(result, first, second);
|
|
30
12
|
// Merge multipleOf
|
|
31
13
|
if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
|
|
32
14
|
result.multipleOf = first.multipleOf * second.multipleOf;
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { genericMerge } from './generic-merge.js';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
4
|
+
import { mergeBounds } from './merge-bounds.js';
|
|
4
5
|
export function mergeNumberConstraints(first, second, getRef) {
|
|
5
6
|
checkTypeConflicts(first, second);
|
|
6
7
|
// First merge enum values if present
|
|
7
8
|
const result = genericMerge(first, second, getRef, v.number());
|
|
8
9
|
// Then merge other constraints
|
|
9
10
|
result.type = 'number';
|
|
10
|
-
|
|
11
|
-
if (first.minimum !== undefined || second.minimum !== undefined) {
|
|
12
|
-
const minA = first.minimum ?? -Infinity;
|
|
13
|
-
const minB = second.minimum ?? -Infinity;
|
|
14
|
-
result.minimum = Math.max(minA, minB);
|
|
15
|
-
// If either minimum is exclusive, the result is exclusive
|
|
16
|
-
if (first.exclusiveMinimum || second.exclusiveMinimum) {
|
|
17
|
-
result.exclusiveMinimum = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Merge maximum and exclusiveMaximum
|
|
21
|
-
if (first.maximum !== undefined || second.maximum !== undefined) {
|
|
22
|
-
const maxA = first.maximum ?? Infinity;
|
|
23
|
-
const maxB = second.maximum ?? Infinity;
|
|
24
|
-
result.maximum = Math.min(maxA, maxB);
|
|
25
|
-
// If either maximum is exclusive, the result is exclusive
|
|
26
|
-
if (first.exclusiveMaximum || second.exclusiveMaximum) {
|
|
27
|
-
result.exclusiveMaximum = true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
11
|
+
mergeBounds(result, first, second);
|
|
30
12
|
// Merge multipleOf
|
|
31
13
|
if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
|
|
32
14
|
result.multipleOf = first.multipleOf * second.multipleOf;
|
|
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
|
|
|
9
9
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
10
10
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
11
11
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
12
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
12
13
|
export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
|
|
13
14
|
const { method, path, pathItem } = operationInfo;
|
|
14
15
|
const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
|
|
@@ -70,9 +71,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
70
71
|
rest: pathItem,
|
|
71
72
|
methodObject: {}
|
|
72
73
|
});
|
|
73
|
-
const
|
|
74
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
74
75
|
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
|
|
75
76
|
: undefined;
|
|
77
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
78
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
76
79
|
return Object.entries(cleaned.methodObject)
|
|
77
80
|
.map(([method, operation]) => {
|
|
78
81
|
// Use `pathStack` (the trail with `path` already pushed),
|
|
@@ -84,6 +87,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
84
87
|
if (!operation) {
|
|
85
88
|
return;
|
|
86
89
|
}
|
|
90
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
87
93
|
try {
|
|
88
94
|
return toOperationV3({
|
|
89
95
|
operation,
|
|
@@ -4,6 +4,7 @@ import type { OpenAPIV3 } from 'openapi-types';
|
|
|
4
4
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
5
5
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
6
6
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
7
|
+
import { type PathParameterList } from '../../pathParameters.js';
|
|
7
8
|
type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
|
|
8
9
|
type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
|
|
9
10
|
export type ToParameterListV3Args = {
|
|
@@ -12,6 +13,12 @@ export type ToParameterListV3Args = {
|
|
|
12
13
|
context: ParseContextType;
|
|
13
14
|
};
|
|
14
15
|
export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Path-level `parameters`: like {@link toParameterListV3}, but an entry
|
|
18
|
+
* that fails to parse is logged and returned in `broken` instead of
|
|
19
|
+
* throwing.
|
|
20
|
+
*/
|
|
21
|
+
export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
|
|
15
22
|
export type ToParametersV3Args = {
|
|
16
23
|
parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
|
|
17
24
|
stackTrail: StackTrail;
|
|
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
10
|
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
11
|
+
import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
|
|
11
12
|
const parameterLocation = v.enum({
|
|
12
13
|
query: 'query',
|
|
13
14
|
header: 'header',
|
|
@@ -23,18 +24,25 @@ const parameterStyle = v.enum({
|
|
|
23
24
|
pipeDelimited: 'pipeDelimited',
|
|
24
25
|
deepObject: 'deepObject'
|
|
25
26
|
});
|
|
26
|
-
export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
|
|
28
|
+
/**
|
|
29
|
+
* Path-level `parameters`: like {@link toParameterListV3}, but an entry
|
|
30
|
+
* that fails to parse is logged and returned in `broken` instead of
|
|
31
|
+
* throwing.
|
|
32
|
+
*/
|
|
33
|
+
export const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
|
|
34
|
+
parameters,
|
|
35
|
+
stackTrail,
|
|
36
|
+
context,
|
|
37
|
+
toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
|
|
38
|
+
});
|
|
39
|
+
const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
|
|
40
|
+
if (isEmptyParameter(parameter)) {
|
|
41
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
42
|
+
return [];
|
|
29
43
|
}
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
44
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
45
|
+
});
|
|
38
46
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
39
47
|
const output = {};
|
|
40
48
|
const entries = Object.entries(parameters);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
3
|
+
import type { BrokenPathParameter } from '../../pathParameters.js';
|
|
3
4
|
import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
|
|
4
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
5
6
|
export type ToPathItemV3Args = {
|
|
@@ -7,4 +8,9 @@ export type ToPathItemV3Args = {
|
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
export
|
|
11
|
+
export type PathItemV3 = {
|
|
12
|
+
pathItem: OasPathItem;
|
|
13
|
+
/** Path-level parameters that failed to parse; the caller drops each operation they apply to. */
|
|
14
|
+
brokenParameters: BrokenPathParameter[];
|
|
15
|
+
};
|
|
16
|
+
export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
|
|
2
2
|
import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
|
|
3
3
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
4
4
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
7
7
|
const { summary, description, parameters, servers, ...skipped } = pathItem;
|
|
8
|
-
|
|
8
|
+
const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
|
|
9
|
+
const oasPathItem = new OasPathItem({
|
|
9
10
|
summary,
|
|
10
11
|
description,
|
|
11
|
-
parameters:
|
|
12
|
+
parameters: pathParameters.parameters,
|
|
12
13
|
servers: tryParseAt({
|
|
13
14
|
stackTrail,
|
|
14
15
|
key: 'servers',
|
|
@@ -25,4 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
|
25
26
|
parentType: 'pathItem'
|
|
26
27
|
})
|
|
27
28
|
});
|
|
29
|
+
return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
|
|
28
30
|
};
|
|
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
|
|
|
9
9
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
10
10
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
11
11
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
12
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
12
13
|
/**
|
|
13
14
|
* Parses a single webhook Operation Object into an {@link OasWebhook}.
|
|
14
15
|
*
|
|
@@ -85,9 +86,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
85
86
|
rest: pathItem,
|
|
86
87
|
methodObject: {}
|
|
87
88
|
});
|
|
88
|
-
const
|
|
89
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
89
90
|
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
|
|
90
91
|
: undefined;
|
|
92
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
93
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
91
94
|
return Object.entries(cleaned.methodObject)
|
|
92
95
|
.map(([method, operation]) => {
|
|
93
96
|
// Use `nameStack` (the trail with the webhook name already
|
|
@@ -97,6 +100,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
97
100
|
if (!operation) {
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
103
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
100
106
|
try {
|
|
101
107
|
return toWebhookV3({
|
|
102
108
|
operation,
|
|
@@ -9,4 +9,6 @@ type DecomposeUnionReturn = {
|
|
|
9
9
|
afterExcluded: SchemaObject;
|
|
10
10
|
};
|
|
11
11
|
export declare const decomposeUnion: ({ schema, groupType }: DecomposeUnionArgs) => DecomposeUnionReturn;
|
|
12
|
+
/** Is `key` a union-level key, kept on the union rather than merged into each member? */
|
|
13
|
+
export declare const isUnionLevelKey: (key: string) => boolean;
|
|
12
14
|
export {};
|
|
@@ -56,9 +56,11 @@ const excludedProperties = [
|
|
|
56
56
|
'writeOnly',
|
|
57
57
|
'deprecated'
|
|
58
58
|
];
|
|
59
|
+
/** Is `key` a union-level key, kept on the union rather than merged into each member? */
|
|
60
|
+
export const isUnionLevelKey = (key) => excludedProperties.includes(key);
|
|
59
61
|
const exclude = (entries) => {
|
|
60
62
|
return entries.reduce((acc, [key, value]) => {
|
|
61
|
-
if (
|
|
63
|
+
if (isUnionLevelKey(key)) {
|
|
62
64
|
acc.excluded.push([key, value]);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SchemaObject } from './types.js';
|
|
2
|
+
export type Bound = {
|
|
3
|
+
value: number;
|
|
4
|
+
exclusive: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** The tighter of two lower bounds. */
|
|
7
|
+
export declare const toTighterMinimum: (first: Bound | undefined, second: Bound | undefined) => Bound | undefined;
|
|
8
|
+
/** The tighter of two upper bounds. */
|
|
9
|
+
export declare const toTighterMaximum: (first: Bound | undefined, second: Bound | undefined) => Bound | undefined;
|
|
10
|
+
/** The lower bound of `schema`; exclusive only when `exclusiveMinimum` is `true`. */
|
|
11
|
+
export declare const toMinimum: (schema: SchemaObject) => Bound | undefined;
|
|
12
|
+
/** The upper bound of `schema`; exclusive only when `exclusiveMaximum` is `true`. */
|
|
13
|
+
export declare const toMaximum: (schema: SchemaObject) => Bound | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
|
|
16
|
+
* of `first` and `second` onto `result`. Members are in the normalized form,
|
|
17
|
+
* where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const mergeBounds: (result: SchemaObject, first: SchemaObject, second: SchemaObject) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Write `minimum` and `maximum` onto `result` in the normalized form. An
|
|
22
|
+
* undefined bound leaves `result` unchanged.
|
|
23
|
+
*/
|
|
24
|
+
export declare const writeBounds: (result: SchemaObject, minimum: Bound | undefined, maximum: Bound | undefined) => void;
|