@skmtc/core 0.44.0 → 0.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,6 +22,8 @@ export type SecurityCheck = {
|
|
|
22
22
|
declaredSchemes: string[];
|
|
23
23
|
/** Declared scheme names that failed to parse. */
|
|
24
24
|
failedSchemes: string[];
|
|
25
|
+
/** Declared scheme names of a valid type core does not parse yet (`mutualTLS`). */
|
|
26
|
+
unmodeledSchemes: string[];
|
|
25
27
|
context: ParseContextType;
|
|
26
28
|
};
|
|
27
29
|
export type ToSecurityCheckArgs = {
|
|
@@ -64,6 +66,10 @@ export type ToOperationsWithValidSecurityArgs<Item extends SecuredItem> = {
|
|
|
64
66
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
65
67
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
66
68
|
* without its auth.
|
|
69
|
+
*
|
|
70
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
71
|
+
* dependency: it is never in the parsed document, and its
|
|
72
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
67
73
|
*/
|
|
68
74
|
export declare const toOperationsWithValidSecurity: <Item extends SecuredItem>({ items, check }: ToOperationsWithValidSecurityArgs<Item>) => Item[];
|
|
69
75
|
export {};
|
|
@@ -68,7 +68,8 @@ const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
|
68
68
|
*/
|
|
69
69
|
export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
70
70
|
const declaredSchemes = Object.keys(declared ?? {});
|
|
71
|
-
const
|
|
71
|
+
const unmodeledSchemes = declaredSchemes.filter(name => isUnmodeledScheme(declared?.[name]));
|
|
72
|
+
const failedSchemes = declaredSchemes.filter(name => !Object.hasOwn(parsed ?? {}, name) && !unmodeledSchemes.includes(name));
|
|
72
73
|
const logRootProblem = (problem) => context.logIssueNoKey({
|
|
73
74
|
stackTrail,
|
|
74
75
|
parent: undefined,
|
|
@@ -80,7 +81,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
80
81
|
const rootSecurity = parse();
|
|
81
82
|
const problems = toSchemeProblems(rootSecurity, { declaredSchemes, failedSchemes });
|
|
82
83
|
if (problems.length === 0) {
|
|
83
|
-
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, context };
|
|
84
|
+
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, unmodeledSchemes, context };
|
|
84
85
|
}
|
|
85
86
|
logRootProblem(`Root security ${problems.join(' and ')}`);
|
|
86
87
|
return {
|
|
@@ -88,6 +89,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
88
89
|
rootProblem: `Inherits root security, which ${problems.join(' and ')}`,
|
|
89
90
|
declaredSchemes,
|
|
90
91
|
failedSchemes,
|
|
92
|
+
unmodeledSchemes,
|
|
91
93
|
context
|
|
92
94
|
};
|
|
93
95
|
}
|
|
@@ -98,6 +100,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
98
100
|
rootProblem: 'Inherits root security, which is not a list of security requirement objects',
|
|
99
101
|
declaredSchemes,
|
|
100
102
|
failedSchemes,
|
|
103
|
+
unmodeledSchemes,
|
|
101
104
|
context
|
|
102
105
|
};
|
|
103
106
|
}
|
|
@@ -113,6 +116,10 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
113
116
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
114
117
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
115
118
|
* without its auth.
|
|
119
|
+
*
|
|
120
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
121
|
+
* dependency: it is never in the parsed document, and its
|
|
122
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
116
123
|
*/
|
|
117
124
|
export const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
118
125
|
return items.filter(item => {
|
|
@@ -121,7 +128,7 @@ export const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
|
121
128
|
: check.rootProblem;
|
|
122
129
|
if (message === undefined) {
|
|
123
130
|
const names = (item.security ?? check.rootSecurity ?? []).flatMap(({ requirement }) => Object.keys(requirement));
|
|
124
|
-
new Set(names).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
131
|
+
new Set(names.filter(name => !check.unmodeledSchemes.includes(name))).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
125
132
|
return true;
|
|
126
133
|
}
|
|
127
134
|
check.context.logIssueNoKey({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skmtc/core",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.2",
|
|
4
4
|
"description": "Skmtc is a declarative code generation framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
"lodash-es": "4.17.21",
|
|
219
219
|
"openapi-types": "^12.1.3",
|
|
220
220
|
"tiny-invariant": "1.3.3",
|
|
221
|
-
"valibot": "1.
|
|
221
|
+
"valibot": "1.5.0",
|
|
222
222
|
"@deno/shim-deno": "^0.19.2"
|
|
223
223
|
},
|
|
224
224
|
"devDependencies": {
|
|
@@ -22,6 +22,8 @@ export type SecurityCheck = {
|
|
|
22
22
|
declaredSchemes: string[];
|
|
23
23
|
/** Declared scheme names that failed to parse. */
|
|
24
24
|
failedSchemes: string[];
|
|
25
|
+
/** Declared scheme names of a valid type core does not parse yet (`mutualTLS`). */
|
|
26
|
+
unmodeledSchemes: string[];
|
|
25
27
|
context: ParseContextType;
|
|
26
28
|
};
|
|
27
29
|
export type ToSecurityCheckArgs = {
|
|
@@ -64,6 +66,10 @@ export type ToOperationsWithValidSecurityArgs<Item extends SecuredItem> = {
|
|
|
64
66
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
65
67
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
66
68
|
* without its auth.
|
|
69
|
+
*
|
|
70
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
71
|
+
* dependency: it is never in the parsed document, and its
|
|
72
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
67
73
|
*/
|
|
68
74
|
export declare const toOperationsWithValidSecurity: <Item extends SecuredItem>({ items, check }: ToOperationsWithValidSecurityArgs<Item>) => Item[];
|
|
69
75
|
export {};
|
|
@@ -72,7 +72,8 @@ const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
|
72
72
|
*/
|
|
73
73
|
const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
74
74
|
const declaredSchemes = Object.keys(declared ?? {});
|
|
75
|
-
const
|
|
75
|
+
const unmodeledSchemes = declaredSchemes.filter(name => isUnmodeledScheme(declared?.[name]));
|
|
76
|
+
const failedSchemes = declaredSchemes.filter(name => !Object.hasOwn(parsed ?? {}, name) && !unmodeledSchemes.includes(name));
|
|
76
77
|
const logRootProblem = (problem) => context.logIssueNoKey({
|
|
77
78
|
stackTrail,
|
|
78
79
|
parent: undefined,
|
|
@@ -84,7 +85,7 @@ const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
|
84
85
|
const rootSecurity = parse();
|
|
85
86
|
const problems = toSchemeProblems(rootSecurity, { declaredSchemes, failedSchemes });
|
|
86
87
|
if (problems.length === 0) {
|
|
87
|
-
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, context };
|
|
88
|
+
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, unmodeledSchemes, context };
|
|
88
89
|
}
|
|
89
90
|
logRootProblem(`Root security ${problems.join(' and ')}`);
|
|
90
91
|
return {
|
|
@@ -92,6 +93,7 @@ const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
|
92
93
|
rootProblem: `Inherits root security, which ${problems.join(' and ')}`,
|
|
93
94
|
declaredSchemes,
|
|
94
95
|
failedSchemes,
|
|
96
|
+
unmodeledSchemes,
|
|
95
97
|
context
|
|
96
98
|
};
|
|
97
99
|
}
|
|
@@ -102,6 +104,7 @@ const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
|
102
104
|
rootProblem: 'Inherits root security, which is not a list of security requirement objects',
|
|
103
105
|
declaredSchemes,
|
|
104
106
|
failedSchemes,
|
|
107
|
+
unmodeledSchemes,
|
|
105
108
|
context
|
|
106
109
|
};
|
|
107
110
|
}
|
|
@@ -118,6 +121,10 @@ exports.toSecurityCheck = toSecurityCheck;
|
|
|
118
121
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
119
122
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
120
123
|
* without its auth.
|
|
124
|
+
*
|
|
125
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
126
|
+
* dependency: it is never in the parsed document, and its
|
|
127
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
121
128
|
*/
|
|
122
129
|
const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
123
130
|
return items.filter(item => {
|
|
@@ -126,7 +133,7 @@ const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
|
126
133
|
: check.rootProblem;
|
|
127
134
|
if (message === undefined) {
|
|
128
135
|
const names = (item.security ?? check.rootSecurity ?? []).flatMap(({ requirement }) => Object.keys(requirement));
|
|
129
|
-
new Set(names).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
136
|
+
new Set(names.filter(name => !check.unmodeledSchemes.includes(name))).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
130
137
|
return true;
|
|
131
138
|
}
|
|
132
139
|
check.context.logIssueNoKey({
|