@skmtc/core 0.35.1 → 0.35.3
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/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -0
- package/esm/parse/pathParameters.d.ts +57 -0
- package/esm/parse/pathParameters.js +138 -0
- package/esm/parse/securityRequirements.d.ts +63 -0
- package/esm/parse/securityRequirements.js +128 -0
- package/esm/parse/toComponentEntries.js +1 -2
- package/esm/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
- 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/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +4 -1
- package/script/parse/pathParameters.d.ts +57 -0
- package/script/parse/pathParameters.js +144 -0
- package/script/parse/securityRequirements.d.ts +63 -0
- package/script/parse/securityRequirements.js +134 -0
- package/script/parse/toComponentEntries.js +1 -2
- package/script/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
|
@@ -2,7 +2,8 @@ import { toRequestBodyV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
|
2
2
|
import { toResponsesV3 } from '../response/toResponseV3.js';
|
|
3
3
|
import { toParameterListV3 } from '../parameter/toParameterV3.js';
|
|
4
4
|
import { OasWebhook } from '../../../oas/webhook/Webhook.js';
|
|
5
|
-
import {
|
|
5
|
+
import { toPathItemV3 } from '../pathItem/toPathItemV3.js';
|
|
6
|
+
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
6
7
|
import { toPathItemMethod } from '../methods.js';
|
|
7
8
|
import { dropAdditionalOperationsV3 } from '../pathItem/dropAdditionalOperationsV3.js';
|
|
8
9
|
import { warnQuerystringConflictsV3 } from '../parameter/warnQuerystringConflictsV3.js';
|
|
@@ -10,6 +11,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
10
11
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
11
12
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
12
13
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
14
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
13
15
|
/**
|
|
14
16
|
* Parses a single webhook Operation Object into an {@link OasWebhook}.
|
|
15
17
|
*
|
|
@@ -88,15 +90,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
88
90
|
rest: fixedFields,
|
|
89
91
|
methodObject: {}
|
|
90
92
|
});
|
|
91
|
-
const pathItemResult =
|
|
92
|
-
pathItem: cleaned.rest,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!pathItemResult.valid) {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
const pathItemObject = pathItemResult.pathItem;
|
|
93
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
94
|
+
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
|
|
95
|
+
: undefined;
|
|
96
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
97
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
100
98
|
return Object.entries(cleaned.methodObject)
|
|
101
99
|
.map(([method, operation]) => {
|
|
102
100
|
// Use `nameStack` (the trail with the webhook name already
|
|
@@ -106,6 +104,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
106
104
|
if (!operation) {
|
|
107
105
|
return;
|
|
108
106
|
}
|
|
107
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
109
110
|
try {
|
|
110
111
|
return toWebhookV3({
|
|
111
112
|
operation,
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ exports.StackTrail = void 0;
|
|
|
16
16
|
require("../_dnt.polyfills.js");
|
|
17
17
|
const Components_js_1 = require("../oas/components/Components.js");
|
|
18
18
|
const JsonPointer_js_1 = require("../types/JsonPointer.js");
|
|
19
|
+
const documentTrail_js_1 = require("./documentTrail.js");
|
|
19
20
|
class StackTrail {
|
|
20
21
|
constructor(stack = []) {
|
|
21
22
|
/** Internal stack of traversal frames */
|
|
@@ -214,15 +215,7 @@ class StackTrail {
|
|
|
214
215
|
* ```
|
|
215
216
|
*/
|
|
216
217
|
toSchemaPointer() {
|
|
217
|
-
|
|
218
|
-
// `post-pass` trace). The operational phase always sits before any
|
|
219
|
-
// document key, so the FIRST match is the boundary — a document key
|
|
220
|
-
// that happens to share a phase name (e.g. a schema literally named
|
|
221
|
-
// `parse`) appears later and is unaffected.
|
|
222
|
-
const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
|
|
223
|
-
const phaseIndex = __classPrivateFieldGet(this, _StackTrail_stack, "f").findIndex(frame => phaseFrames.has(frame));
|
|
224
|
-
const documentFrames = phaseIndex === -1 ? __classPrivateFieldGet(this, _StackTrail_stack, "f") : __classPrivateFieldGet(this, _StackTrail_stack, "f").slice(phaseIndex + 1);
|
|
225
|
-
return (0, JsonPointer_js_1.toJsonPointer)(documentFrames);
|
|
218
|
+
return (0, JsonPointer_js_1.toJsonPointer)((0, documentTrail_js_1.toDocumentFrames)(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
|
|
226
219
|
}
|
|
227
220
|
toStackRef() {
|
|
228
221
|
const [first, second, third] = this.stackTrail;
|
|
@@ -308,9 +301,7 @@ class StackTrail {
|
|
|
308
301
|
* ```
|
|
309
302
|
*/
|
|
310
303
|
toString() {
|
|
311
|
-
return __classPrivateFieldGet(this, _StackTrail_stack, "f")
|
|
312
|
-
.map(frame => frame.replace(/[%:]/g, character => escapes[character]))
|
|
313
|
-
.join(':');
|
|
304
|
+
return (0, documentTrail_js_1.toTrailString)(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
|
|
314
305
|
}
|
|
315
306
|
/**
|
|
316
307
|
* Reads a string written by {@link StackTrail.toString} back into a trail.
|
|
@@ -334,5 +325,4 @@ class StackTrail {
|
|
|
334
325
|
}
|
|
335
326
|
exports.StackTrail = StackTrail;
|
|
336
327
|
_StackTrail_stack = new WeakMap();
|
|
337
|
-
const escapes = { '%': '%25', ':': '%3A' };
|
|
338
328
|
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,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDocumentString = exports.toDocumentFrames = exports.toTrailString = void 0;
|
|
4
|
+
const escapes = { '%': '%25', ':': '%3A' };
|
|
5
|
+
// Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
|
|
6
|
+
// `post-pass` trace).
|
|
7
|
+
const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
|
|
8
|
+
/** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
|
|
9
|
+
const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
|
|
10
|
+
exports.toTrailString = toTrailString;
|
|
11
|
+
/**
|
|
12
|
+
* The frames of a trail that address the input document: everything after
|
|
13
|
+
* the first phase frame, or every frame when there is no phase frame.
|
|
14
|
+
*/
|
|
15
|
+
const toDocumentFrames = (frames) => {
|
|
16
|
+
// The operational phase always sits before any document key, so the
|
|
17
|
+
// FIRST match is the boundary — a document key that happens to share a
|
|
18
|
+
// phase name (e.g. a schema literally named `parse`) appears later and
|
|
19
|
+
// is unaffected.
|
|
20
|
+
const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
|
|
21
|
+
return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
|
|
22
|
+
};
|
|
23
|
+
exports.toDocumentFrames = toDocumentFrames;
|
|
24
|
+
/**
|
|
25
|
+
* The document-relative trail in `StackTrail.toString` form.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
|
|
30
|
+
* // 'paths:/pets:parameters:0'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const toDocumentString = (frames) => (0, exports.toTrailString)((0, exports.toDocumentFrames)(frames));
|
|
34
|
+
exports.toDocumentString = toDocumentString;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/** A non-null object that is not an array. */
|
|
2
2
|
export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
3
|
+
/** Name the kind of a value for an error message: `null`, `an array`, or its `typeof`. */
|
|
4
|
+
export declare const toKind: (value: unknown) => string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPlainObject = void 0;
|
|
3
|
+
exports.toKind = exports.isPlainObject = void 0;
|
|
4
4
|
/** A non-null object that is not an array. */
|
|
5
5
|
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
6
|
exports.isPlainObject = isPlainObject;
|
|
7
|
+
/** Name the kind of a value for an error message: `null`, `an array`, or its `typeof`. */
|
|
8
|
+
const toKind = (value) => value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
|
|
9
|
+
exports.toKind = toKind;
|
|
@@ -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,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDroppedByPathParameter = exports.toPathParameterList = exports.toParameterEntries = void 0;
|
|
4
|
+
const emptyParameter_js_1 = require("./emptyParameter.js");
|
|
5
|
+
const documentTrail_js_1 = require("../context/documentTrail.js");
|
|
6
|
+
/**
|
|
7
|
+
* Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
|
|
8
|
+
* is read as no parameters with an `EMPTY_PARAMETER` warning at the
|
|
9
|
+
* field. Any other value that is not an array throws.
|
|
10
|
+
*/
|
|
11
|
+
const toParameterEntries = ({ parameters, stackTrail, context }) => {
|
|
12
|
+
if (parameters === undefined) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(parameters)) {
|
|
16
|
+
return parameters;
|
|
17
|
+
}
|
|
18
|
+
if ((0, emptyParameter_js_1.isEmptyParameter)(parameters)) {
|
|
19
|
+
context.logIssueNoKey({
|
|
20
|
+
stackTrail,
|
|
21
|
+
parent: parameters,
|
|
22
|
+
level: 'warning',
|
|
23
|
+
type: 'EMPTY_PARAMETER',
|
|
24
|
+
message: 'Empty parameters field; read as no parameters'
|
|
25
|
+
});
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Expected parameters to be an array but received ${typeof parameters}`);
|
|
29
|
+
};
|
|
30
|
+
exports.toParameterEntries = toParameterEntries;
|
|
31
|
+
const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
32
|
+
const toNameAndIn = (parameter) => {
|
|
33
|
+
if (typeof parameter === 'object' &&
|
|
34
|
+
parameter !== null &&
|
|
35
|
+
'name' in parameter &&
|
|
36
|
+
'in' in parameter &&
|
|
37
|
+
typeof parameter.name === 'string' &&
|
|
38
|
+
typeof parameter.in === 'string') {
|
|
39
|
+
return { name: parameter.name, in: parameter.in };
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Parses a path item's `parameters` without letting a throw escape. Each
|
|
45
|
+
* entry that fails logs one `INVALID_PARAMETER` error at its index and is
|
|
46
|
+
* returned in `broken`; a field that is not an array logs one at the field.
|
|
47
|
+
* The caller decides per operation which broken entries apply.
|
|
48
|
+
*/
|
|
49
|
+
const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
|
|
50
|
+
const logBroken = (st, parent, error) => {
|
|
51
|
+
const normalized = toError(error);
|
|
52
|
+
context.logIssueNoKey({
|
|
53
|
+
level: 'error',
|
|
54
|
+
stackTrail: st,
|
|
55
|
+
parent,
|
|
56
|
+
message: normalized.message,
|
|
57
|
+
cause: normalized,
|
|
58
|
+
type: 'INVALID_PARAMETER'
|
|
59
|
+
});
|
|
60
|
+
return { location: (0, documentTrail_js_1.toDocumentString)(st.stackTrail), message: normalized.message };
|
|
61
|
+
};
|
|
62
|
+
const readEntries = () => {
|
|
63
|
+
try {
|
|
64
|
+
return { entries: (0, exports.toParameterEntries)({ parameters, stackTrail, context }) };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// A field that is not an array cannot be matched to an override.
|
|
68
|
+
return { broken: logBroken(stackTrail, parameters, error) };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const read = readEntries();
|
|
72
|
+
if ('broken' in read) {
|
|
73
|
+
return { parameters: undefined, broken: [read.broken] };
|
|
74
|
+
}
|
|
75
|
+
if (read.entries === undefined) {
|
|
76
|
+
return { parameters: undefined, broken: [] };
|
|
77
|
+
}
|
|
78
|
+
const results = read.entries.map((parameter, index) => {
|
|
79
|
+
try {
|
|
80
|
+
return { parsed: toEntry({ parameter, index }), broken: [] };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
return {
|
|
84
|
+
parsed: [],
|
|
85
|
+
broken: [
|
|
86
|
+
{
|
|
87
|
+
...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
|
|
88
|
+
...toNameAndIn(parameter)
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
parameters: results.flatMap(({ parsed }) => parsed),
|
|
96
|
+
broken: results.flatMap(({ broken }) => broken)
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
exports.toPathParameterList = toPathParameterList;
|
|
100
|
+
/**
|
|
101
|
+
* The first broken path-level parameter that applies to an operation. An
|
|
102
|
+
* entry applies unless it has a readable `name` and `in` and the
|
|
103
|
+
* operation's inline `parameters` hold the same pair, which overrides it.
|
|
104
|
+
* A `$ref` operation parameter cannot be resolved during parse, so it
|
|
105
|
+
* overrides nothing.
|
|
106
|
+
*/
|
|
107
|
+
const toApplyingBrokenParameter = ({ broken, operation }) => {
|
|
108
|
+
if (broken.length === 0) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const operationParameters = typeof operation === 'object' &&
|
|
112
|
+
operation !== null &&
|
|
113
|
+
'parameters' in operation &&
|
|
114
|
+
Array.isArray(operation.parameters)
|
|
115
|
+
? operation.parameters
|
|
116
|
+
: [];
|
|
117
|
+
const overrides = new Set(operationParameters.flatMap((parameter) => {
|
|
118
|
+
const { name, in: parameterIn } = toNameAndIn(parameter);
|
|
119
|
+
return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
|
|
120
|
+
}));
|
|
121
|
+
return broken.find(entry => entry.name === undefined ||
|
|
122
|
+
entry.in === undefined ||
|
|
123
|
+
!overrides.has(`${entry.in}:${entry.name}`));
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* True when a broken path-level parameter applies to the operation. Logs
|
|
127
|
+
* one `INVALID_OPERATION` error at the operation that names the first
|
|
128
|
+
* such entry.
|
|
129
|
+
*/
|
|
130
|
+
const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
|
|
131
|
+
const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
|
|
132
|
+
if (!broken) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
context.logIssueNoKey({
|
|
136
|
+
parent: operation,
|
|
137
|
+
level: 'error',
|
|
138
|
+
message: `Path-level parameter ${broken.location} failed to parse: ${broken.message}`,
|
|
139
|
+
stackTrail,
|
|
140
|
+
type: 'INVALID_OPERATION'
|
|
141
|
+
});
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
exports.isDroppedByPathParameter = isDroppedByPathParameter;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
import type { OasSecurityRequirement } from '../oas/securityRequirement/SecurityRequirement.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check a `security` field before its requirements are parsed. Shared by
|
|
6
|
+
* the 3.0, 3.1 and 3.2 parsers.
|
|
7
|
+
*
|
|
8
|
+
* - Missing: returns `undefined`.
|
|
9
|
+
* - Not an array, or an entry that is not an object of scheme name to a
|
|
10
|
+
* list of string scopes: throws, so the operation is dropped as
|
|
11
|
+
* `INVALID_OPERATION`. At the root, {@link toSecurityCheck} catches it.
|
|
12
|
+
* - Otherwise: returns the checked requirement objects.
|
|
13
|
+
*/
|
|
14
|
+
export declare const toSecurityRequirementObjects: (security: unknown) => Record<string, string[]>[] | undefined;
|
|
15
|
+
/** The document-level facts each operation's security is checked against. */
|
|
16
|
+
export type SecurityCheck = {
|
|
17
|
+
/** The parsed root `security`; `undefined` when absent or malformed. */
|
|
18
|
+
rootSecurity: OasSecurityRequirement[] | undefined;
|
|
19
|
+
/** Why the root `security` cannot be used, or `undefined` when it can. */
|
|
20
|
+
rootProblem: string | undefined;
|
|
21
|
+
/** Scheme names in the document's `components.securitySchemes`. */
|
|
22
|
+
declaredSchemes: string[];
|
|
23
|
+
/** Declared scheme names that failed to parse. */
|
|
24
|
+
failedSchemes: string[];
|
|
25
|
+
context: ParseContextType;
|
|
26
|
+
};
|
|
27
|
+
export type ToSecurityCheckArgs = {
|
|
28
|
+
/** Parses the root `security`; throws when it is malformed. */
|
|
29
|
+
parse: () => OasSecurityRequirement[] | undefined;
|
|
30
|
+
/** The raw `components.securitySchemes`. */
|
|
31
|
+
declared: Record<string, unknown> | undefined;
|
|
32
|
+
/** The parsed `components.securitySchemes`. */
|
|
33
|
+
parsed: Record<string, unknown> | undefined;
|
|
34
|
+
/** Trail that ends in the root `security` key. */
|
|
35
|
+
stackTrail: StackTrail;
|
|
36
|
+
context: ParseContextType;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Parse the document's root `security` and collect the scheme facts that
|
|
40
|
+
* {@link toOperationsWithValidSecurity} checks each operation against.
|
|
41
|
+
*
|
|
42
|
+
* A root `security` that is malformed, or that names a scheme that failed
|
|
43
|
+
* to parse or is not defined, logs one `INVALID_OPERATION` warning at
|
|
44
|
+
* `security` and sets `rootProblem`. The document then has no `security`,
|
|
45
|
+
* and the operations that inherit it are dropped.
|
|
46
|
+
*/
|
|
47
|
+
export declare const toSecurityCheck: ({ parse, declared, parsed, stackTrail, context }: ToSecurityCheckArgs) => SecurityCheck;
|
|
48
|
+
type SecuredItem = {
|
|
49
|
+
security: OasSecurityRequirement[] | undefined;
|
|
50
|
+
stackTrail: StackTrail;
|
|
51
|
+
};
|
|
52
|
+
export type ToOperationsWithValidSecurityArgs<Item extends SecuredItem> = {
|
|
53
|
+
items: Item[];
|
|
54
|
+
check: SecurityCheck;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Drop each operation or webhook whose own `security` names a scheme that
|
|
58
|
+
* failed to parse or is not defined, or that has no `security` and
|
|
59
|
+
* inherits an unusable root. Each dropped item logs one `INVALID_OPERATION`
|
|
60
|
+
* error on its own trail. `security: []` inherits nothing and is kept.
|
|
61
|
+
*/
|
|
62
|
+
export declare const toOperationsWithValidSecurity: <Item extends SecuredItem>({ items, check }: ToOperationsWithValidSecurityArgs<Item>) => Item[];
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toOperationsWithValidSecurity = exports.toSecurityCheck = exports.toSecurityRequirementObjects = void 0;
|
|
4
|
+
const isPlainObject_js_1 = require("./isPlainObject.js");
|
|
5
|
+
const isScopeList = (value) => Array.isArray(value) && value.every((scope) => typeof scope === 'string');
|
|
6
|
+
const toRequirementObject = (requirement, index) => {
|
|
7
|
+
if (!(0, isPlainObject_js_1.isPlainObject)(requirement)) {
|
|
8
|
+
throw new Error(`"security" entry ${index} must be a security requirement object, got ${(0, isPlainObject_js_1.toKind)(requirement)}`);
|
|
9
|
+
}
|
|
10
|
+
return Object.fromEntries(Object.entries(requirement).map(([name, scopes]) => {
|
|
11
|
+
if (!isScopeList(scopes)) {
|
|
12
|
+
throw new Error(`"security" entry ${index} must map each scheme name to a list of scopes; '${name}' does not`);
|
|
13
|
+
}
|
|
14
|
+
return [name, scopes];
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check a `security` field before its requirements are parsed. Shared by
|
|
19
|
+
* the 3.0, 3.1 and 3.2 parsers.
|
|
20
|
+
*
|
|
21
|
+
* - Missing: returns `undefined`.
|
|
22
|
+
* - Not an array, or an entry that is not an object of scheme name to a
|
|
23
|
+
* list of string scopes: throws, so the operation is dropped as
|
|
24
|
+
* `INVALID_OPERATION`. At the root, {@link toSecurityCheck} catches it.
|
|
25
|
+
* - Otherwise: returns the checked requirement objects.
|
|
26
|
+
*/
|
|
27
|
+
const toSecurityRequirementObjects = (security) => {
|
|
28
|
+
if (security === undefined) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(security)) {
|
|
32
|
+
throw new Error(`"security" must be a list of security requirement objects, got ${(0, isPlainObject_js_1.toKind)(security)}`);
|
|
33
|
+
}
|
|
34
|
+
return security.map((requirement, index) => toRequirementObject(requirement, index));
|
|
35
|
+
};
|
|
36
|
+
exports.toSecurityRequirementObjects = toSecurityRequirementObjects;
|
|
37
|
+
// Valid scheme types that core does not parse yet. Such a scheme logs
|
|
38
|
+
// INVALID_SECURITY_SCHEME but is not counted as failed, so the operations
|
|
39
|
+
// that require it are kept, as before.
|
|
40
|
+
const unmodeledSchemeTypes = ['mutualTLS'];
|
|
41
|
+
const isUnmodeledScheme = (scheme) => (0, isPlainObject_js_1.isPlainObject)(scheme) &&
|
|
42
|
+
typeof scheme.type === 'string' &&
|
|
43
|
+
unmodeledSchemeTypes.includes(scheme.type);
|
|
44
|
+
const quote = (names) => names.map(name => `'${name}'`).join(', ');
|
|
45
|
+
const toSchemeProblem = (names, reason) => {
|
|
46
|
+
const one = names.length === 1;
|
|
47
|
+
return `requires security ${one ? 'scheme' : 'schemes'} ${quote(names)}, which ${reason(one)}`;
|
|
48
|
+
};
|
|
49
|
+
/** One lowercase clause per kind of unusable scheme in `security`. */
|
|
50
|
+
const toSchemeProblems = (security, { declaredSchemes, failedSchemes }) => {
|
|
51
|
+
const names = [
|
|
52
|
+
...new Set((security ?? []).flatMap(({ requirement }) => Object.keys(requirement)))
|
|
53
|
+
];
|
|
54
|
+
const failed = names.filter(name => failedSchemes.includes(name));
|
|
55
|
+
const undefinedNames = names.filter(name => !declaredSchemes.includes(name));
|
|
56
|
+
return [
|
|
57
|
+
failed.length > 0 ? toSchemeProblem(failed, () => 'failed to parse') : undefined,
|
|
58
|
+
undefinedNames.length > 0
|
|
59
|
+
? toSchemeProblem(undefinedNames, one => `${one ? 'is' : 'are'} not defined in components.securitySchemes`)
|
|
60
|
+
: undefined
|
|
61
|
+
].filter(part => part !== undefined);
|
|
62
|
+
};
|
|
63
|
+
const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
64
|
+
/**
|
|
65
|
+
* Parse the document's root `security` and collect the scheme facts that
|
|
66
|
+
* {@link toOperationsWithValidSecurity} checks each operation against.
|
|
67
|
+
*
|
|
68
|
+
* A root `security` that is malformed, or that names a scheme that failed
|
|
69
|
+
* to parse or is not defined, logs one `INVALID_OPERATION` warning at
|
|
70
|
+
* `security` and sets `rootProblem`. The document then has no `security`,
|
|
71
|
+
* and the operations that inherit it are dropped.
|
|
72
|
+
*/
|
|
73
|
+
const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
74
|
+
const declaredSchemes = Object.keys(declared ?? {});
|
|
75
|
+
const failedSchemes = declaredSchemes.filter(name => !Object.hasOwn(parsed ?? {}, name) && !isUnmodeledScheme(declared?.[name]));
|
|
76
|
+
const logRootProblem = (problem) => context.logIssueNoKey({
|
|
77
|
+
stackTrail,
|
|
78
|
+
parent: undefined,
|
|
79
|
+
level: 'warning',
|
|
80
|
+
type: 'INVALID_OPERATION',
|
|
81
|
+
message: `${problem}; root security is left out and operations that inherit it are dropped`
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
const rootSecurity = parse();
|
|
85
|
+
const problems = toSchemeProblems(rootSecurity, { declaredSchemes, failedSchemes });
|
|
86
|
+
if (problems.length === 0) {
|
|
87
|
+
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, context };
|
|
88
|
+
}
|
|
89
|
+
logRootProblem(`Root security ${problems.join(' and ')}`);
|
|
90
|
+
return {
|
|
91
|
+
rootSecurity: undefined,
|
|
92
|
+
rootProblem: `Inherits root security, which ${problems.join(' and ')}`,
|
|
93
|
+
declaredSchemes,
|
|
94
|
+
failedSchemes,
|
|
95
|
+
context
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
logRootProblem(error instanceof Error ? error.message : String(error));
|
|
100
|
+
return {
|
|
101
|
+
rootSecurity: undefined,
|
|
102
|
+
rootProblem: 'Inherits root security, which is not a list of security requirement objects',
|
|
103
|
+
declaredSchemes,
|
|
104
|
+
failedSchemes,
|
|
105
|
+
context
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
exports.toSecurityCheck = toSecurityCheck;
|
|
110
|
+
/**
|
|
111
|
+
* Drop each operation or webhook whose own `security` names a scheme that
|
|
112
|
+
* failed to parse or is not defined, or that has no `security` and
|
|
113
|
+
* inherits an unusable root. Each dropped item logs one `INVALID_OPERATION`
|
|
114
|
+
* error on its own trail. `security: []` inherits nothing and is kept.
|
|
115
|
+
*/
|
|
116
|
+
const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
117
|
+
return items.filter(item => {
|
|
118
|
+
const message = item.security
|
|
119
|
+
? toSchemeProblems(item.security, check).map(capitalize).join('. ') || undefined
|
|
120
|
+
: check.rootProblem;
|
|
121
|
+
if (message === undefined) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
check.context.logIssueNoKey({
|
|
125
|
+
stackTrail: item.stackTrail,
|
|
126
|
+
parent: undefined,
|
|
127
|
+
level: 'error',
|
|
128
|
+
type: 'INVALID_OPERATION',
|
|
129
|
+
message
|
|
130
|
+
});
|
|
131
|
+
return false;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
exports.toOperationsWithValidSecurity = toOperationsWithValidSecurity;
|
|
@@ -22,7 +22,7 @@ const toComponentEntries = ({ entries, stackTrail, context, type, label, parse }
|
|
|
22
22
|
parent: entry,
|
|
23
23
|
fn: st => {
|
|
24
24
|
if (!(0, isPlainObject_js_1.isPlainObject)(entry)) {
|
|
25
|
-
throw new Error(`${label} must be an object, got ${toKind(entry)}`);
|
|
25
|
+
throw new Error(`${label} must be an object, got ${(0, isPlainObject_js_1.toKind)(entry)}`);
|
|
26
26
|
}
|
|
27
27
|
return parse({ key, entry, stackTrail: st });
|
|
28
28
|
}
|
|
@@ -32,4 +32,3 @@ const toComponentEntries = ({ entries, stackTrail, context, type, label, parse }
|
|
|
32
32
|
return Object.fromEntries(parsedEntries);
|
|
33
33
|
};
|
|
34
34
|
exports.toComponentEntries = toComponentEntries;
|
|
35
|
-
const toKind = (value) => value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
|
|
@@ -10,6 +10,7 @@ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toS
|
|
|
10
10
|
const toServerV3_js_1 = require("../server/toServerV3.js");
|
|
11
11
|
const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityRequirement.js");
|
|
12
12
|
const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
|
|
13
|
+
const securityRequirements_js_1 = require("../../securityRequirements.js");
|
|
13
14
|
const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
14
15
|
const { openapi, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
15
16
|
const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
|
|
@@ -19,15 +20,28 @@ const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
19
20
|
stackTrail,
|
|
20
21
|
parentType: 'document'
|
|
21
22
|
});
|
|
23
|
+
const parsedInfo = stackTrail.trace('info', st => (0, toInfoV3_js_1.toInfoV3)({ info, stackTrail: st, context }));
|
|
24
|
+
const parsedServers = stackTrail.trace('servers', st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context }));
|
|
25
|
+
const parsedOperations = stackTrail.trace('paths', st => (0, toOperationsV3_js_1.toOperationsV3)({ paths, stackTrail: st, context }));
|
|
26
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => (0, toWebhooksV3_js_1.toWebhooksV3)({ webhooks, stackTrail: st, context }));
|
|
27
|
+
const parsedComponents = stackTrail.trace('components', st => (0, toComponentsV3_js_1.toComponentsV3)({ components, stackTrail: st, context }));
|
|
28
|
+
const parsedTags = stackTrail.trace('tags', st => (0, toTagsV3_js_1.toTagsV3)({ tags, stackTrail: st, context }));
|
|
29
|
+
const securityCheck = stackTrail.trace('security', st => (0, securityRequirements_js_1.toSecurityCheck)({
|
|
30
|
+
parse: () => (0, toSecurityRequirement_js_1.toSecurityRequirementsV3)({ security, stackTrail: st, context }),
|
|
31
|
+
declared: components?.securitySchemes,
|
|
32
|
+
parsed: parsedComponents?.securitySchemes,
|
|
33
|
+
stackTrail: st,
|
|
34
|
+
context
|
|
35
|
+
}));
|
|
22
36
|
return {
|
|
23
37
|
openapi,
|
|
24
|
-
info:
|
|
25
|
-
servers:
|
|
26
|
-
operations:
|
|
27
|
-
webhooks:
|
|
28
|
-
components:
|
|
29
|
-
tags:
|
|
30
|
-
security:
|
|
38
|
+
info: parsedInfo,
|
|
39
|
+
servers: parsedServers,
|
|
40
|
+
operations: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedOperations, check: securityCheck }),
|
|
41
|
+
webhooks: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedWebhooks, check: securityCheck }),
|
|
42
|
+
components: parsedComponents,
|
|
43
|
+
tags: parsedTags,
|
|
44
|
+
security: securityCheck.rootSecurity,
|
|
31
45
|
extensionFields,
|
|
32
46
|
externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context }))
|
|
33
47
|
};
|
|
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
|
|
|
12
12
|
const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
|
|
13
13
|
const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
|
|
14
14
|
const toServerV3_js_1 = require("../server/toServerV3.js");
|
|
15
|
+
const pathParameters_js_1 = require("../../pathParameters.js");
|
|
15
16
|
const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
|
|
16
17
|
const { method, path, pathItem } = operationInfo;
|
|
17
18
|
const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
|
|
@@ -74,9 +75,11 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
74
75
|
rest: pathItem,
|
|
75
76
|
methodObject: {}
|
|
76
77
|
});
|
|
77
|
-
const
|
|
78
|
+
const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
|
|
78
79
|
? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: pathStack, context })
|
|
79
80
|
: undefined;
|
|
81
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
82
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
80
83
|
return Object.entries(cleaned.methodObject)
|
|
81
84
|
.map(([method, operation]) => {
|
|
82
85
|
// Use `pathStack` (the trail with `path` already pushed),
|
|
@@ -88,6 +91,9 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
88
91
|
if (!operation) {
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
94
|
+
if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
91
97
|
try {
|
|
92
98
|
return (0, exports.toOperationV3)({
|
|
93
99
|
operation,
|