@skmtc/core 0.35.2 → 0.36.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/_dnt.polyfills.d.ts +6 -6
- package/esm/context/ParseContext.d.ts +22 -29
- package/esm/context/ParseContext.js +179 -82
- package/esm/context/tryParseAt.js +3 -3
- package/esm/gql/document/GqlDocument.js +22 -6
- package/esm/gql/document/parseGqlDocument.js +3 -1
- package/esm/oas/components/Components.d.ts +10 -0
- package/esm/oas/components/Components.js +64 -0
- package/esm/oas/document/Document.d.ts +7 -7
- package/esm/oas/document/Document.js +6 -4
- package/esm/parse/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -0
- package/esm/parse/pathParameters.d.ts +13 -0
- package/esm/parse/pathParameters.js +2 -2
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- 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-2/document/toDocumentFieldsV3.js +21 -7
- package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
- package/package.json +1 -1
- package/script/_dnt.polyfills.d.ts +6 -6
- package/script/context/ParseContext.d.ts +22 -29
- package/script/context/ParseContext.js +179 -82
- package/script/context/tryParseAt.js +3 -3
- package/script/gql/document/GqlDocument.js +22 -6
- package/script/gql/document/parseGqlDocument.js +3 -1
- package/script/oas/components/Components.d.ts +10 -0
- package/script/oas/components/Components.js +64 -0
- package/script/oas/document/Document.d.ts +7 -7
- package/script/oas/document/Document.js +6 -4
- package/script/parse/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +4 -1
- package/script/parse/pathParameters.d.ts +13 -0
- package/script/parse/pathParameters.js +6 -4
- 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/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- 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-2/document/toDocumentFieldsV3.js +21 -7
- package/script/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
import type { OasTag } from '../tag/Tag.js';
|
|
3
|
-
import type { OasComponents } from '../components/Components.js';
|
|
3
|
+
import type { ComponentsEntry, OasComponents } from '../components/Components.js';
|
|
4
4
|
import type { OasOperation } from '../operation/Operation.js';
|
|
5
5
|
import type { OasWebhook } from '../webhook/Webhook.js';
|
|
6
6
|
import type { OasInfo } from '../info/Info.js';
|
|
7
7
|
import type { OasServer } from '../server/Server.js';
|
|
8
8
|
import type { OasSecurityRequirement } from '../securityRequirement/SecurityRequirement.js';
|
|
9
9
|
import type { StackTrail } from '../../context/StackTrail.js';
|
|
10
|
-
import type { OasSchema } from '../schema/Schema.js';
|
|
11
|
-
import type { OasRef } from '../ref/Ref.js';
|
|
12
10
|
import type { OasExternalDocs } from '../externalDocs/ExternalDocs.js';
|
|
13
11
|
/**
|
|
14
12
|
* Fields that define the structure of an OpenAPI v3 document.
|
|
@@ -179,10 +177,12 @@ export declare class OasDocument {
|
|
|
179
177
|
* Removes an item from the document based on a stack trail path.
|
|
180
178
|
*
|
|
181
179
|
* This method is used internally during document processing to remove
|
|
182
|
-
* specific operations or
|
|
183
|
-
* the path to the item within the document structure.
|
|
180
|
+
* specific operations, webhooks or components. The stack trail indicates
|
|
181
|
+
* the path to the item within the document structure. A
|
|
182
|
+
* `components:<bucket>:<name>` trail removes the entry from that bucket
|
|
183
|
+
* (`components:requestBodies:X` removes request body `X`, not schema `X`).
|
|
184
184
|
*
|
|
185
|
-
* @param stackTrail -
|
|
185
|
+
* @param stackTrail - Document-relative path to the item to remove
|
|
186
186
|
* @returns The removed item, or undefined if not found
|
|
187
187
|
*
|
|
188
188
|
* @internal This method is primarily used by the processing pipeline
|
|
@@ -196,7 +196,7 @@ export declare class OasDocument {
|
|
|
196
196
|
* const removedSchema = document.removeItem(new StackTrail(['components', 'schemas', 'User']));
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
removeItem(stackTrail: StackTrail): OasOperation | OasWebhook |
|
|
199
|
+
removeItem(stackTrail: StackTrail): OasOperation | OasWebhook | ComponentsEntry | undefined;
|
|
200
200
|
/**
|
|
201
201
|
* Sets the document fields after parsing.
|
|
202
202
|
*
|
|
@@ -148,10 +148,12 @@ class OasDocument {
|
|
|
148
148
|
* Removes an item from the document based on a stack trail path.
|
|
149
149
|
*
|
|
150
150
|
* This method is used internally during document processing to remove
|
|
151
|
-
* specific operations or
|
|
152
|
-
* the path to the item within the document structure.
|
|
151
|
+
* specific operations, webhooks or components. The stack trail indicates
|
|
152
|
+
* the path to the item within the document structure. A
|
|
153
|
+
* `components:<bucket>:<name>` trail removes the entry from that bucket
|
|
154
|
+
* (`components:requestBodies:X` removes request body `X`, not schema `X`).
|
|
153
155
|
*
|
|
154
|
-
* @param stackTrail -
|
|
156
|
+
* @param stackTrail - Document-relative path to the item to remove
|
|
155
157
|
* @returns The removed item, or undefined if not found
|
|
156
158
|
*
|
|
157
159
|
* @internal This method is primarily used by the processing pipeline
|
|
@@ -192,7 +194,7 @@ class OasDocument {
|
|
|
192
194
|
if (typeof third !== 'string') {
|
|
193
195
|
throw new Error(`RefName cannot be a number: ${third}`);
|
|
194
196
|
}
|
|
195
|
-
return __classPrivateFieldGet(this, _OasDocument_fields, "f")
|
|
197
|
+
return __classPrivateFieldGet(this, _OasDocument_fields, "f")?.components?.removeEntry(second, third);
|
|
196
198
|
}
|
|
197
199
|
default:
|
|
198
200
|
throw new Error(`Unexpected stack trail: ${stackTrail}`);
|
|
@@ -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;
|
|
@@ -35,6 +35,7 @@ export type ToPathParameterListArgs<Entry, Parameter> = {
|
|
|
35
35
|
index: number;
|
|
36
36
|
}) => Parameter[];
|
|
37
37
|
};
|
|
38
|
+
export declare const toNameAndIn: (parameter: unknown) => Pick<BrokenPathParameter, "name" | "in">;
|
|
38
39
|
/**
|
|
39
40
|
* Parses a path item's `parameters` without letting a throw escape. Each
|
|
40
41
|
* entry that fails logs one `INVALID_PARAMETER` error at its index and is
|
|
@@ -42,6 +43,18 @@ export type ToPathParameterListArgs<Entry, Parameter> = {
|
|
|
42
43
|
* The caller decides per operation which broken entries apply.
|
|
43
44
|
*/
|
|
44
45
|
export declare const toPathParameterList: <Entry, Parameter>({ parameters, stackTrail, context, toEntry }: ToPathParameterListArgs<Entry, Parameter>) => PathParameterList<Parameter>;
|
|
46
|
+
/**
|
|
47
|
+
* The first broken path-level parameter that applies to an operation. An
|
|
48
|
+
* entry applies unless it has a readable `name` and `in` and the
|
|
49
|
+
* operation's inline `parameters` hold the same pair, which overrides it.
|
|
50
|
+
* A `$ref` operation parameter cannot be resolved during parse, so it
|
|
51
|
+
* overrides nothing.
|
|
52
|
+
*/
|
|
53
|
+
export declare const toApplyingBrokenParameter: ({ broken, operation }: {
|
|
54
|
+
broken: BrokenPathParameter[];
|
|
55
|
+
/** The raw operation object. */
|
|
56
|
+
operation: unknown;
|
|
57
|
+
}) => BrokenPathParameter | undefined;
|
|
45
58
|
/**
|
|
46
59
|
* True when a broken path-level parameter applies to the operation. Logs
|
|
47
60
|
* one `INVALID_OPERATION` error at the operation that names the first
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDroppedByPathParameter = exports.toPathParameterList = exports.toParameterEntries = void 0;
|
|
3
|
+
exports.isDroppedByPathParameter = exports.toApplyingBrokenParameter = exports.toPathParameterList = exports.toNameAndIn = exports.toParameterEntries = void 0;
|
|
4
4
|
const emptyParameter_js_1 = require("./emptyParameter.js");
|
|
5
5
|
const documentTrail_js_1 = require("../context/documentTrail.js");
|
|
6
6
|
/**
|
|
@@ -40,6 +40,7 @@ const toNameAndIn = (parameter) => {
|
|
|
40
40
|
}
|
|
41
41
|
return {};
|
|
42
42
|
};
|
|
43
|
+
exports.toNameAndIn = toNameAndIn;
|
|
43
44
|
/**
|
|
44
45
|
* Parses a path item's `parameters` without letting a throw escape. Each
|
|
45
46
|
* entry that fails logs one `INVALID_PARAMETER` error at its index and is
|
|
@@ -85,7 +86,7 @@ const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
|
|
|
85
86
|
broken: [
|
|
86
87
|
{
|
|
87
88
|
...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
|
|
88
|
-
...toNameAndIn(parameter)
|
|
89
|
+
...(0, exports.toNameAndIn)(parameter)
|
|
89
90
|
}
|
|
90
91
|
]
|
|
91
92
|
};
|
|
@@ -115,20 +116,21 @@ const toApplyingBrokenParameter = ({ broken, operation }) => {
|
|
|
115
116
|
? operation.parameters
|
|
116
117
|
: [];
|
|
117
118
|
const overrides = new Set(operationParameters.flatMap((parameter) => {
|
|
118
|
-
const { name, in: parameterIn } = toNameAndIn(parameter);
|
|
119
|
+
const { name, in: parameterIn } = (0, exports.toNameAndIn)(parameter);
|
|
119
120
|
return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
|
|
120
121
|
}));
|
|
121
122
|
return broken.find(entry => entry.name === undefined ||
|
|
122
123
|
entry.in === undefined ||
|
|
123
124
|
!overrides.has(`${entry.in}:${entry.name}`));
|
|
124
125
|
};
|
|
126
|
+
exports.toApplyingBrokenParameter = toApplyingBrokenParameter;
|
|
125
127
|
/**
|
|
126
128
|
* True when a broken path-level parameter applies to the operation. Logs
|
|
127
129
|
* one `INVALID_OPERATION` error at the operation that names the first
|
|
128
130
|
* such entry.
|
|
129
131
|
*/
|
|
130
132
|
const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
|
|
131
|
-
const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
|
|
133
|
+
const broken = (0, exports.toApplyingBrokenParameter)({ broken: brokenParameters, operation });
|
|
132
134
|
if (!broken) {
|
|
133
135
|
return false;
|
|
134
136
|
}
|
|
@@ -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
|
};
|
|
@@ -2,7 +2,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
2
2
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
3
3
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
4
4
|
export type ToSecurityRequirementsV3Args = {
|
|
5
|
-
security
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toSecurityRequirementsV3 = void 0;
|
|
4
4
|
const SecurityRequirement_js_1 = require("../../../oas/securityRequirement/SecurityRequirement.js");
|
|
5
|
+
const securityRequirements_js_1 = require("../../securityRequirements.js");
|
|
5
6
|
const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
6
|
-
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return security.map(requirement => {
|
|
7
|
+
return (0, securityRequirements_js_1.toSecurityRequirementObjects)(security)?.map(requirement => {
|
|
10
8
|
return new SecurityRequirement_js_1.OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
11
9
|
});
|
|
12
10
|
};
|
|
@@ -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
|
};
|
|
@@ -2,7 +2,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
2
2
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
3
3
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
4
4
|
export type ToSecurityRequirementsV3Args = {
|
|
5
|
-
security
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toSecurityRequirementsV3 = void 0;
|
|
4
4
|
const SecurityRequirement_js_1 = require("../../../oas/securityRequirement/SecurityRequirement.js");
|
|
5
|
+
const securityRequirements_js_1 = require("../../securityRequirements.js");
|
|
5
6
|
const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
6
|
-
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return security.map(requirement => {
|
|
7
|
+
return (0, securityRequirements_js_1.toSecurityRequirementObjects)(security)?.map(requirement => {
|
|
10
8
|
return new SecurityRequirement_js_1.OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
11
9
|
});
|
|
12
10
|
};
|
|
@@ -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, $self, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
15
16
|
const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
|
|
@@ -19,16 +20,29 @@ 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
38
|
$self,
|
|
25
|
-
info:
|
|
26
|
-
servers:
|
|
27
|
-
operations:
|
|
28
|
-
webhooks:
|
|
29
|
-
components:
|
|
30
|
-
tags:
|
|
31
|
-
security:
|
|
39
|
+
info: parsedInfo,
|
|
40
|
+
servers: parsedServers,
|
|
41
|
+
operations: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedOperations, check: securityCheck }),
|
|
42
|
+
webhooks: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedWebhooks, check: securityCheck }),
|
|
43
|
+
components: parsedComponents,
|
|
44
|
+
tags: parsedTags,
|
|
45
|
+
security: securityCheck.rootSecurity,
|
|
32
46
|
extensionFields,
|
|
33
47
|
externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context }))
|
|
34
48
|
};
|
|
@@ -2,7 +2,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
2
2
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
3
3
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
4
4
|
export type ToSecurityRequirementsV3Args = {
|
|
5
|
-
security
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toSecurityRequirementsV3 = void 0;
|
|
4
4
|
const SecurityRequirement_js_1 = require("../../../oas/securityRequirement/SecurityRequirement.js");
|
|
5
|
+
const securityRequirements_js_1 = require("../../securityRequirements.js");
|
|
5
6
|
const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
6
|
-
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return security.map(requirement => {
|
|
7
|
+
return (0, securityRequirements_js_1.toSecurityRequirementObjects)(security)?.map(requirement => {
|
|
10
8
|
return new SecurityRequirement_js_1.OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
11
9
|
});
|
|
12
10
|
};
|