@skmtc/core 0.35.2 → 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/parse/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -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/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/parse/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +4 -1
- 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,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,2 +1,4 @@
|
|
|
1
1
|
/** A non-null object that is not an array. */
|
|
2
2
|
export const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
/** Name the kind of a value for an error message: `null`, `an array`, or its `typeof`. */
|
|
4
|
+
export const toKind = (value) => value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
|
|
@@ -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,128 @@
|
|
|
1
|
+
import { isPlainObject, toKind } from './isPlainObject.js';
|
|
2
|
+
const isScopeList = (value) => Array.isArray(value) && value.every((scope) => typeof scope === 'string');
|
|
3
|
+
const toRequirementObject = (requirement, index) => {
|
|
4
|
+
if (!isPlainObject(requirement)) {
|
|
5
|
+
throw new Error(`"security" entry ${index} must be a security requirement object, got ${toKind(requirement)}`);
|
|
6
|
+
}
|
|
7
|
+
return Object.fromEntries(Object.entries(requirement).map(([name, scopes]) => {
|
|
8
|
+
if (!isScopeList(scopes)) {
|
|
9
|
+
throw new Error(`"security" entry ${index} must map each scheme name to a list of scopes; '${name}' does not`);
|
|
10
|
+
}
|
|
11
|
+
return [name, scopes];
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Check a `security` field before its requirements are parsed. Shared by
|
|
16
|
+
* the 3.0, 3.1 and 3.2 parsers.
|
|
17
|
+
*
|
|
18
|
+
* - Missing: returns `undefined`.
|
|
19
|
+
* - Not an array, or an entry that is not an object of scheme name to a
|
|
20
|
+
* list of string scopes: throws, so the operation is dropped as
|
|
21
|
+
* `INVALID_OPERATION`. At the root, {@link toSecurityCheck} catches it.
|
|
22
|
+
* - Otherwise: returns the checked requirement objects.
|
|
23
|
+
*/
|
|
24
|
+
export const toSecurityRequirementObjects = (security) => {
|
|
25
|
+
if (security === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (!Array.isArray(security)) {
|
|
29
|
+
throw new Error(`"security" must be a list of security requirement objects, got ${toKind(security)}`);
|
|
30
|
+
}
|
|
31
|
+
return security.map((requirement, index) => toRequirementObject(requirement, index));
|
|
32
|
+
};
|
|
33
|
+
// Valid scheme types that core does not parse yet. Such a scheme logs
|
|
34
|
+
// INVALID_SECURITY_SCHEME but is not counted as failed, so the operations
|
|
35
|
+
// that require it are kept, as before.
|
|
36
|
+
const unmodeledSchemeTypes = ['mutualTLS'];
|
|
37
|
+
const isUnmodeledScheme = (scheme) => isPlainObject(scheme) &&
|
|
38
|
+
typeof scheme.type === 'string' &&
|
|
39
|
+
unmodeledSchemeTypes.includes(scheme.type);
|
|
40
|
+
const quote = (names) => names.map(name => `'${name}'`).join(', ');
|
|
41
|
+
const toSchemeProblem = (names, reason) => {
|
|
42
|
+
const one = names.length === 1;
|
|
43
|
+
return `requires security ${one ? 'scheme' : 'schemes'} ${quote(names)}, which ${reason(one)}`;
|
|
44
|
+
};
|
|
45
|
+
/** One lowercase clause per kind of unusable scheme in `security`. */
|
|
46
|
+
const toSchemeProblems = (security, { declaredSchemes, failedSchemes }) => {
|
|
47
|
+
const names = [
|
|
48
|
+
...new Set((security ?? []).flatMap(({ requirement }) => Object.keys(requirement)))
|
|
49
|
+
];
|
|
50
|
+
const failed = names.filter(name => failedSchemes.includes(name));
|
|
51
|
+
const undefinedNames = names.filter(name => !declaredSchemes.includes(name));
|
|
52
|
+
return [
|
|
53
|
+
failed.length > 0 ? toSchemeProblem(failed, () => 'failed to parse') : undefined,
|
|
54
|
+
undefinedNames.length > 0
|
|
55
|
+
? toSchemeProblem(undefinedNames, one => `${one ? 'is' : 'are'} not defined in components.securitySchemes`)
|
|
56
|
+
: undefined
|
|
57
|
+
].filter(part => part !== undefined);
|
|
58
|
+
};
|
|
59
|
+
const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
60
|
+
/**
|
|
61
|
+
* Parse the document's root `security` and collect the scheme facts that
|
|
62
|
+
* {@link toOperationsWithValidSecurity} checks each operation against.
|
|
63
|
+
*
|
|
64
|
+
* A root `security` that is malformed, or that names a scheme that failed
|
|
65
|
+
* to parse or is not defined, logs one `INVALID_OPERATION` warning at
|
|
66
|
+
* `security` and sets `rootProblem`. The document then has no `security`,
|
|
67
|
+
* and the operations that inherit it are dropped.
|
|
68
|
+
*/
|
|
69
|
+
export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
70
|
+
const declaredSchemes = Object.keys(declared ?? {});
|
|
71
|
+
const failedSchemes = declaredSchemes.filter(name => !Object.hasOwn(parsed ?? {}, name) && !isUnmodeledScheme(declared?.[name]));
|
|
72
|
+
const logRootProblem = (problem) => context.logIssueNoKey({
|
|
73
|
+
stackTrail,
|
|
74
|
+
parent: undefined,
|
|
75
|
+
level: 'warning',
|
|
76
|
+
type: 'INVALID_OPERATION',
|
|
77
|
+
message: `${problem}; root security is left out and operations that inherit it are dropped`
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
const rootSecurity = parse();
|
|
81
|
+
const problems = toSchemeProblems(rootSecurity, { declaredSchemes, failedSchemes });
|
|
82
|
+
if (problems.length === 0) {
|
|
83
|
+
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, context };
|
|
84
|
+
}
|
|
85
|
+
logRootProblem(`Root security ${problems.join(' and ')}`);
|
|
86
|
+
return {
|
|
87
|
+
rootSecurity: undefined,
|
|
88
|
+
rootProblem: `Inherits root security, which ${problems.join(' and ')}`,
|
|
89
|
+
declaredSchemes,
|
|
90
|
+
failedSchemes,
|
|
91
|
+
context
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logRootProblem(error instanceof Error ? error.message : String(error));
|
|
96
|
+
return {
|
|
97
|
+
rootSecurity: undefined,
|
|
98
|
+
rootProblem: 'Inherits root security, which is not a list of security requirement objects',
|
|
99
|
+
declaredSchemes,
|
|
100
|
+
failedSchemes,
|
|
101
|
+
context
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Drop each operation or webhook whose own `security` names a scheme that
|
|
107
|
+
* failed to parse or is not defined, or that has no `security` and
|
|
108
|
+
* inherits an unusable root. Each dropped item logs one `INVALID_OPERATION`
|
|
109
|
+
* error on its own trail. `security: []` inherits nothing and is kept.
|
|
110
|
+
*/
|
|
111
|
+
export const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
112
|
+
return items.filter(item => {
|
|
113
|
+
const message = item.security
|
|
114
|
+
? toSchemeProblems(item.security, check).map(capitalize).join('. ') || undefined
|
|
115
|
+
: check.rootProblem;
|
|
116
|
+
if (message === undefined) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
check.context.logIssueNoKey({
|
|
120
|
+
stackTrail: item.stackTrail,
|
|
121
|
+
parent: undefined,
|
|
122
|
+
level: 'error',
|
|
123
|
+
type: 'INVALID_OPERATION',
|
|
124
|
+
message
|
|
125
|
+
});
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tryParseAt } from '../context/tryParseAt.js';
|
|
2
|
-
import { isPlainObject } from './isPlainObject.js';
|
|
2
|
+
import { isPlainObject, toKind } from './isPlainObject.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parse each entry of a `components` bucket inside its own `tryParseAt`
|
|
5
5
|
* boundary. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
@@ -28,4 +28,3 @@ export const toComponentEntries = ({ entries, stackTrail, context, type, label,
|
|
|
28
28
|
});
|
|
29
29
|
return Object.fromEntries(parsedEntries);
|
|
30
30
|
};
|
|
31
|
-
const toKind = (value) => value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
|
|
@@ -7,6 +7,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
7
7
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
8
8
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
9
9
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
10
|
+
import { toOperationsWithValidSecurity, toSecurityCheck } from '../../securityRequirements.js';
|
|
10
11
|
export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
11
12
|
const { openapi, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
12
13
|
const extensionFields = toSpecificationExtensionsV3({
|
|
@@ -16,15 +17,28 @@ export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
16
17
|
stackTrail,
|
|
17
18
|
parentType: 'document'
|
|
18
19
|
});
|
|
20
|
+
const parsedInfo = stackTrail.trace('info', st => toInfoV3({ info, stackTrail: st, context }));
|
|
21
|
+
const parsedServers = stackTrail.trace('servers', st => toOptionalServersV3({ servers, stackTrail: st, context }));
|
|
22
|
+
const parsedOperations = stackTrail.trace('paths', st => toOperationsV3({ paths, stackTrail: st, context }));
|
|
23
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => toWebhooksV3({ webhooks, stackTrail: st, context }));
|
|
24
|
+
const parsedComponents = stackTrail.trace('components', st => toComponentsV3({ components, stackTrail: st, context }));
|
|
25
|
+
const parsedTags = stackTrail.trace('tags', st => toTagsV3({ tags, stackTrail: st, context }));
|
|
26
|
+
const securityCheck = stackTrail.trace('security', st => toSecurityCheck({
|
|
27
|
+
parse: () => toSecurityRequirementsV3({ security, stackTrail: st, context }),
|
|
28
|
+
declared: components?.securitySchemes,
|
|
29
|
+
parsed: parsedComponents?.securitySchemes,
|
|
30
|
+
stackTrail: st,
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
19
33
|
return {
|
|
20
34
|
openapi,
|
|
21
|
-
info:
|
|
22
|
-
servers:
|
|
23
|
-
operations:
|
|
24
|
-
webhooks:
|
|
25
|
-
components:
|
|
26
|
-
tags:
|
|
27
|
-
security:
|
|
35
|
+
info: parsedInfo,
|
|
36
|
+
servers: parsedServers,
|
|
37
|
+
operations: toOperationsWithValidSecurity({ items: parsedOperations, check: securityCheck }),
|
|
38
|
+
webhooks: toOperationsWithValidSecurity({ items: parsedWebhooks, check: securityCheck }),
|
|
39
|
+
components: parsedComponents,
|
|
40
|
+
tags: parsedTags,
|
|
41
|
+
security: securityCheck.rootSecurity,
|
|
28
42
|
extensionFields,
|
|
29
43
|
externalDocs: stackTrail.trace('externalDocs', st => toExternalDocs({ externalDocs, stackTrail: st, context }))
|
|
30
44
|
};
|
|
@@ -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
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|
|
@@ -7,6 +7,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
7
7
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
8
8
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
9
9
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
10
|
+
import { toOperationsWithValidSecurity, toSecurityCheck } from '../../securityRequirements.js';
|
|
10
11
|
export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
11
12
|
const { openapi, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
12
13
|
const extensionFields = toSpecificationExtensionsV3({
|
|
@@ -16,15 +17,28 @@ export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
16
17
|
stackTrail,
|
|
17
18
|
parentType: 'document'
|
|
18
19
|
});
|
|
20
|
+
const parsedInfo = stackTrail.trace('info', st => toInfoV3({ info, stackTrail: st, context }));
|
|
21
|
+
const parsedServers = stackTrail.trace('servers', st => toOptionalServersV3({ servers, stackTrail: st, context }));
|
|
22
|
+
const parsedOperations = stackTrail.trace('paths', st => toOperationsV3({ paths, stackTrail: st, context }));
|
|
23
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => toWebhooksV3({ webhooks, stackTrail: st, context }));
|
|
24
|
+
const parsedComponents = stackTrail.trace('components', st => toComponentsV3({ components, stackTrail: st, context }));
|
|
25
|
+
const parsedTags = stackTrail.trace('tags', st => toTagsV3({ tags, stackTrail: st, context }));
|
|
26
|
+
const securityCheck = stackTrail.trace('security', st => toSecurityCheck({
|
|
27
|
+
parse: () => toSecurityRequirementsV3({ security, stackTrail: st, context }),
|
|
28
|
+
declared: components?.securitySchemes,
|
|
29
|
+
parsed: parsedComponents?.securitySchemes,
|
|
30
|
+
stackTrail: st,
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
19
33
|
return {
|
|
20
34
|
openapi,
|
|
21
|
-
info:
|
|
22
|
-
servers:
|
|
23
|
-
operations:
|
|
24
|
-
webhooks:
|
|
25
|
-
components:
|
|
26
|
-
tags:
|
|
27
|
-
security:
|
|
35
|
+
info: parsedInfo,
|
|
36
|
+
servers: parsedServers,
|
|
37
|
+
operations: toOperationsWithValidSecurity({ items: parsedOperations, check: securityCheck }),
|
|
38
|
+
webhooks: toOperationsWithValidSecurity({ items: parsedWebhooks, check: securityCheck }),
|
|
39
|
+
components: parsedComponents,
|
|
40
|
+
tags: parsedTags,
|
|
41
|
+
security: securityCheck.rootSecurity,
|
|
28
42
|
extensionFields,
|
|
29
43
|
externalDocs: stackTrail.trace('externalDocs', st => toExternalDocs({ externalDocs, stackTrail: st, context }))
|
|
30
44
|
};
|
|
@@ -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
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|
|
@@ -7,6 +7,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
7
7
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
8
8
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
9
9
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
10
|
+
import { toOperationsWithValidSecurity, toSecurityCheck } from '../../securityRequirements.js';
|
|
10
11
|
export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
11
12
|
const { openapi, $self, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
12
13
|
const extensionFields = toSpecificationExtensionsV3({
|
|
@@ -16,16 +17,29 @@ export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
16
17
|
stackTrail,
|
|
17
18
|
parentType: 'document'
|
|
18
19
|
});
|
|
20
|
+
const parsedInfo = stackTrail.trace('info', st => toInfoV3({ info, stackTrail: st, context }));
|
|
21
|
+
const parsedServers = stackTrail.trace('servers', st => toOptionalServersV3({ servers, stackTrail: st, context }));
|
|
22
|
+
const parsedOperations = stackTrail.trace('paths', st => toOperationsV3({ paths, stackTrail: st, context }));
|
|
23
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => toWebhooksV3({ webhooks, stackTrail: st, context }));
|
|
24
|
+
const parsedComponents = stackTrail.trace('components', st => toComponentsV3({ components, stackTrail: st, context }));
|
|
25
|
+
const parsedTags = stackTrail.trace('tags', st => toTagsV3({ tags, stackTrail: st, context }));
|
|
26
|
+
const securityCheck = stackTrail.trace('security', st => toSecurityCheck({
|
|
27
|
+
parse: () => toSecurityRequirementsV3({ security, stackTrail: st, context }),
|
|
28
|
+
declared: components?.securitySchemes,
|
|
29
|
+
parsed: parsedComponents?.securitySchemes,
|
|
30
|
+
stackTrail: st,
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
19
33
|
return {
|
|
20
34
|
openapi,
|
|
21
35
|
$self,
|
|
22
|
-
info:
|
|
23
|
-
servers:
|
|
24
|
-
operations:
|
|
25
|
-
webhooks:
|
|
26
|
-
components:
|
|
27
|
-
tags:
|
|
28
|
-
security:
|
|
36
|
+
info: parsedInfo,
|
|
37
|
+
servers: parsedServers,
|
|
38
|
+
operations: toOperationsWithValidSecurity({ items: parsedOperations, check: securityCheck }),
|
|
39
|
+
webhooks: toOperationsWithValidSecurity({ items: parsedWebhooks, check: securityCheck }),
|
|
40
|
+
components: parsedComponents,
|
|
41
|
+
tags: parsedTags,
|
|
42
|
+
security: securityCheck.rootSecurity,
|
|
29
43
|
extensionFields,
|
|
30
44
|
externalDocs: stackTrail.trace('externalDocs', st => toExternalDocs({ externalDocs, stackTrail: st, context }))
|
|
31
45
|
};
|
|
@@ -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
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|
package/package.json
CHANGED
|
@@ -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,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
|
};
|