@scalar/oas-utils 0.2.105 → 0.2.106
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/CHANGELOG.md
CHANGED
|
@@ -16,7 +16,7 @@ export declare const parseSchema: (spec: string | UnknownObject, { shouldLoad }?
|
|
|
16
16
|
errors: import("@scalar/openapi-parser").ErrorObject[];
|
|
17
17
|
}>;
|
|
18
18
|
/** Converts selected security requirements to uids */
|
|
19
|
-
export declare const getSelectedSecuritySchemeUids: (securityRequirements: SelectedSecuritySchemeUids,
|
|
19
|
+
export declare const getSelectedSecuritySchemeUids: (securityRequirements: SelectedSecuritySchemeUids, preferredSecurityNames: SelectedSecuritySchemeUids | undefined, securitySchemeMap: Record<string, string>) => SelectedSecuritySchemeUids;
|
|
20
20
|
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers'> & {
|
|
21
21
|
/** Sets the preferred security scheme on the collection instead of the requests */
|
|
22
22
|
setCollectionSecurity?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAWjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA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,CAAA;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,GAAG,aAAa,EAC5B,EACE,cAAc,EACd,aAAa,EACb,WAAW,EACX,OAAO,EAAE,iBAAiB,EAC1B,qBAA6B,EAC7B,UAAU,EACV,SAAiB,GAClB,GAAE,yBAA8B,GAChC,OAAO,CACN;IACE,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CAuWA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAM,GACpE,MAAM,EAAE,CA8CV"}
|
|
@@ -51,29 +51,13 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
53
|
/** Converts selected security requirements to uids */
|
|
54
|
-
const getSelectedSecuritySchemeUids = (securityRequirements,
|
|
55
|
-
// Filter the preferred security schemes to only include the ones that are in the security requirements
|
|
56
|
-
const preferredSecurityNames = [
|
|
57
|
-
authentication?.preferredSecurityScheme ?? [],
|
|
58
|
-
]
|
|
59
|
-
.flat()
|
|
60
|
-
.filter((name) => {
|
|
61
|
-
// Match up complex security requirements, array to array
|
|
62
|
-
if (Array.isArray(name)) {
|
|
63
|
-
// We match every element in the array
|
|
64
|
-
return securityRequirements.some((r) => Array.isArray(r) &&
|
|
65
|
-
r.length === name.length &&
|
|
66
|
-
r.every((v, i) => v === name[i]));
|
|
67
|
-
}
|
|
68
|
-
else
|
|
69
|
-
return securityRequirements.includes(name);
|
|
70
|
-
});
|
|
54
|
+
const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNames = [], securitySchemeMap) => {
|
|
71
55
|
// Set the first security requirement if no preferred security schemes are set
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
const names = securityRequirements[0] && !preferredSecurityNames.length
|
|
57
|
+
? [securityRequirements[0]]
|
|
58
|
+
: preferredSecurityNames;
|
|
75
59
|
// Map names to uids
|
|
76
|
-
const uids =
|
|
60
|
+
const uids = names.map((name) => Array.isArray(name)
|
|
77
61
|
? name.map((k) => securitySchemeMap[k])
|
|
78
62
|
: securitySchemeMap[name]);
|
|
79
63
|
return uids;
|
|
@@ -212,9 +196,25 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
212
196
|
return keys.length > 1 ? keys : keys[0];
|
|
213
197
|
})
|
|
214
198
|
.filter(isDefined);
|
|
199
|
+
// Filter the preferred security schemes to only include the ones that are in the security requirements
|
|
200
|
+
const preferredSecurityNames = [
|
|
201
|
+
authentication?.preferredSecurityScheme ?? [],
|
|
202
|
+
]
|
|
203
|
+
.flat()
|
|
204
|
+
.filter((name) => {
|
|
205
|
+
// Match up complex security requirements, array to array
|
|
206
|
+
if (Array.isArray(name)) {
|
|
207
|
+
// We match every element in the array
|
|
208
|
+
return securityRequirements.some((r) => Array.isArray(r) &&
|
|
209
|
+
r.length === name.length &&
|
|
210
|
+
r.every((v, i) => v === name[i]));
|
|
211
|
+
}
|
|
212
|
+
else
|
|
213
|
+
return securityRequirements.includes(name);
|
|
214
|
+
});
|
|
215
215
|
// Set the initially selected security scheme
|
|
216
216
|
const selectedSecuritySchemeUids = securityRequirements.length && !setCollectionSecurity
|
|
217
|
-
? getSelectedSecuritySchemeUids(securityRequirements,
|
|
217
|
+
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
218
218
|
: [];
|
|
219
219
|
const requestPayload = {
|
|
220
220
|
...operationWithoutSecurity,
|
|
@@ -307,13 +307,20 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
307
307
|
// ---------------------------------------------------------------------------
|
|
308
308
|
// Generate Collection
|
|
309
309
|
// Grab the security requirements for this operation
|
|
310
|
-
const securityRequirements = (schema.security ?? [])
|
|
310
|
+
const securityRequirements = (schema.security ?? [])
|
|
311
|
+
.map((s) => {
|
|
311
312
|
const keys = Object.keys(s);
|
|
312
313
|
return keys.length > 1 ? keys : keys[0];
|
|
313
|
-
})
|
|
314
|
+
})
|
|
315
|
+
.filter(isDefined);
|
|
316
|
+
// Here we do not filter these as we let the preferredSecurityScheme override the requirements
|
|
317
|
+
const preferredSecurityNames = [
|
|
318
|
+
authentication?.preferredSecurityScheme ?? [],
|
|
319
|
+
].flat();
|
|
314
320
|
// Set the initially selected security scheme
|
|
315
|
-
const selectedSecuritySchemeUids = securityRequirements.length &&
|
|
316
|
-
|
|
321
|
+
const selectedSecuritySchemeUids = (securityRequirements.length || preferredSecurityNames?.length) &&
|
|
322
|
+
setCollectionSecurity
|
|
323
|
+
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
317
324
|
: [];
|
|
318
325
|
const collection = collectionSchema.parse({
|
|
319
326
|
...schema,
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.106",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -126,10 +126,10 @@
|
|
|
126
126
|
"nanoid": "^5.0.9",
|
|
127
127
|
"yaml": "^2.4.5",
|
|
128
128
|
"zod": "^3.23.8",
|
|
129
|
+
"@scalar/openapi-types": "0.1.7",
|
|
129
130
|
"@scalar/object-utils": "1.1.13",
|
|
130
|
-
"@scalar/themes": "0.9.67",
|
|
131
131
|
"@scalar/types": "0.0.33",
|
|
132
|
-
"@scalar/
|
|
132
|
+
"@scalar/themes": "0.9.67"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
135
|
"type-fest": "^4.20.0",
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
"vitest": "^1.6.0",
|
|
138
138
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
139
139
|
"@scalar/build-tooling": "0.1.13",
|
|
140
|
-
"@scalar/openapi-
|
|
141
|
-
"@scalar/openapi-
|
|
140
|
+
"@scalar/openapi-parser": "0.10.7",
|
|
141
|
+
"@scalar/openapi-types": "0.1.7"
|
|
142
142
|
},
|
|
143
143
|
"scripts": {
|
|
144
144
|
"build": "scalar-build-rollup",
|