@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
|
*
|
|
@@ -145,10 +145,12 @@ export class OasDocument {
|
|
|
145
145
|
* Removes an item from the document based on a stack trail path.
|
|
146
146
|
*
|
|
147
147
|
* This method is used internally during document processing to remove
|
|
148
|
-
* specific operations or
|
|
149
|
-
* the path to the item within the document structure.
|
|
148
|
+
* specific operations, webhooks or components. The stack trail indicates
|
|
149
|
+
* the path to the item within the document structure. A
|
|
150
|
+
* `components:<bucket>:<name>` trail removes the entry from that bucket
|
|
151
|
+
* (`components:requestBodies:X` removes request body `X`, not schema `X`).
|
|
150
152
|
*
|
|
151
|
-
* @param stackTrail -
|
|
153
|
+
* @param stackTrail - Document-relative path to the item to remove
|
|
152
154
|
* @returns The removed item, or undefined if not found
|
|
153
155
|
*
|
|
154
156
|
* @internal This method is primarily used by the processing pipeline
|
|
@@ -189,7 +191,7 @@ export class OasDocument {
|
|
|
189
191
|
if (typeof third !== 'string') {
|
|
190
192
|
throw new Error(`RefName cannot be a number: ${third}`);
|
|
191
193
|
}
|
|
192
|
-
return __classPrivateFieldGet(this, _OasDocument_fields, "f")
|
|
194
|
+
return __classPrivateFieldGet(this, _OasDocument_fields, "f")?.components?.removeEntry(second, third);
|
|
193
195
|
}
|
|
194
196
|
default:
|
|
195
197
|
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,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;
|
|
@@ -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
|
|
@@ -25,7 +25,7 @@ export const toParameterEntries = ({ parameters, stackTrail, context }) => {
|
|
|
25
25
|
throw new Error(`Expected parameters to be an array but received ${typeof parameters}`);
|
|
26
26
|
};
|
|
27
27
|
const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
28
|
-
const toNameAndIn = (parameter) => {
|
|
28
|
+
export const toNameAndIn = (parameter) => {
|
|
29
29
|
if (typeof parameter === 'object' &&
|
|
30
30
|
parameter !== null &&
|
|
31
31
|
'name' in parameter &&
|
|
@@ -99,7 +99,7 @@ export const toPathParameterList = ({ parameters, stackTrail, context, toEntry }
|
|
|
99
99
|
* A `$ref` operation parameter cannot be resolved during parse, so it
|
|
100
100
|
* overrides nothing.
|
|
101
101
|
*/
|
|
102
|
-
const toApplyingBrokenParameter = ({ broken, operation }) => {
|
|
102
|
+
export const toApplyingBrokenParameter = ({ broken, operation }) => {
|
|
103
103
|
if (broken.length === 0) {
|
|
104
104
|
return undefined;
|
|
105
105
|
}
|
|
@@ -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,9 +1,3 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Error {
|
|
3
|
-
cause?: unknown;
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export {};
|
|
7
1
|
declare global {
|
|
8
2
|
interface Object {
|
|
9
3
|
/**
|
|
@@ -15,6 +9,12 @@ declare global {
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
export {};
|
|
12
|
+
declare global {
|
|
13
|
+
interface Error {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
18
|
/**
|
|
19
19
|
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
20
20
|
* but instead of using npm to install additional dependencies,
|