@scalar/oas-utils 0.2.105 → 0.2.107
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 +19 -0
- package/dist/entities/cookie/cookie.d.ts +2 -2
- package/dist/entities/cookie/cookie.js +1 -1
- package/dist/entities/environment/environment.d.ts +2 -2
- package/dist/entities/environment/environment.js +1 -1
- package/dist/entities/shared/utility.d.ts +13 -1
- package/dist/entities/shared/utility.d.ts.map +1 -1
- package/dist/entities/shared/utility.js +4 -1
- package/dist/entities/spec/collection.d.ts +46 -46
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +11 -16
- package/dist/entities/spec/operation.d.ts +22 -22
- package/dist/entities/spec/parameters.d.ts +4 -4
- package/dist/entities/spec/request-examples.d.ts +5 -5
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +25 -62
- package/dist/entities/spec/requests.d.ts +30 -30
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +6 -18
- package/dist/entities/spec/security.d.ts +22 -22
- package/dist/entities/spec/security.d.ts.map +1 -1
- package/dist/entities/spec/security.js +7 -22
- package/dist/entities/spec/server.d.ts +2 -2
- package/dist/entities/spec/server.d.ts.map +1 -1
- package/dist/entities/spec/server.js +3 -5
- package/dist/entities/spec/spec-objects.d.ts +5 -5
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +6 -3
- package/dist/entities/spec/x-scalar-secrets.d.ts +4 -4
- package/dist/entities/spec/x-scalar-secrets.d.ts.map +1 -1
- package/dist/entities/workspace/workspace.d.ts +7 -7
- package/dist/entities/workspace/workspace.d.ts.map +1 -1
- package/dist/entities/workspace/workspace.js +5 -5
- package/dist/helpers/fetchSpecFromUrl.d.ts.map +1 -1
- package/dist/helpers/fetchSpecFromUrl.js +1 -1
- package/dist/helpers/json2xml.d.ts.map +1 -1
- package/dist/helpers/json2xml.js +3 -7
- package/dist/migrations/migrator.d.ts +1 -1
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.d.ts +1 -1
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +66 -3
- package/dist/migrations/v-2.5.0/types.generated.d.ts +17 -17
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
- package/dist/transforms/import-spec.d.ts +1 -1
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +26 -41
- package/package.json +7 -7
|
@@ -51,31 +51,11 @@ 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
|
-
preferredSecurityNames.push(securityRequirements[0]);
|
|
74
|
-
}
|
|
56
|
+
const names = securityRequirements[0] && !preferredSecurityNames.length ? [securityRequirements[0]] : preferredSecurityNames;
|
|
75
57
|
// Map names to uids
|
|
76
|
-
const uids =
|
|
77
|
-
? name.map((k) => securitySchemeMap[k])
|
|
78
|
-
: securitySchemeMap[name]);
|
|
58
|
+
const uids = names.map((name) => Array.isArray(name) ? name.map((k) => securitySchemeMap[k]) : securitySchemeMap[name]);
|
|
79
59
|
return uids;
|
|
80
60
|
};
|
|
81
61
|
/**
|
|
@@ -195,26 +175,31 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
195
175
|
const methods = Object.keys(path).filter(isHttpMethod);
|
|
196
176
|
methods.forEach((method) => {
|
|
197
177
|
const operation = path[method];
|
|
198
|
-
const operationServers = serverSchema
|
|
199
|
-
.array()
|
|
200
|
-
.parse(operation.servers ?? []);
|
|
178
|
+
const operationServers = serverSchema.array().parse(operation.servers ?? []);
|
|
201
179
|
servers.push(...operationServers);
|
|
202
180
|
// We will save a list of all tags to ensure they exists at the top level
|
|
203
181
|
// TODO: make sure we add any loose requests with no tags to the collection children
|
|
204
182
|
operation.tags?.forEach((t) => tagNames.add(t));
|
|
205
183
|
// Remove security here and add it correctly below
|
|
206
184
|
const { security: operationSecurity, ...operationWithoutSecurity } = operation;
|
|
207
|
-
const securityRequirements = (operationSecurity ??
|
|
208
|
-
schema.security ??
|
|
209
|
-
[])
|
|
185
|
+
const securityRequirements = (operationSecurity ?? schema.security ?? [])
|
|
210
186
|
.map((s) => {
|
|
211
187
|
const keys = Object.keys(s);
|
|
212
188
|
return keys.length > 1 ? keys : keys[0];
|
|
213
189
|
})
|
|
214
190
|
.filter(isDefined);
|
|
191
|
+
// Filter the preferred security schemes to only include the ones that are in the security requirements
|
|
192
|
+
const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat().filter((name) => {
|
|
193
|
+
// Match up complex security requirements, array to array
|
|
194
|
+
if (Array.isArray(name)) {
|
|
195
|
+
// We match every element in the array
|
|
196
|
+
return securityRequirements.some((r) => Array.isArray(r) && r.length === name.length && r.every((v, i) => v === name[i]));
|
|
197
|
+
}
|
|
198
|
+
return securityRequirements.includes(name);
|
|
199
|
+
});
|
|
215
200
|
// Set the initially selected security scheme
|
|
216
201
|
const selectedSecuritySchemeUids = securityRequirements.length && !setCollectionSecurity
|
|
217
|
-
? getSelectedSecuritySchemeUids(securityRequirements,
|
|
202
|
+
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
218
203
|
: [];
|
|
219
204
|
const requestPayload = {
|
|
220
205
|
...operationWithoutSecurity,
|
|
@@ -223,10 +208,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
223
208
|
security: operationSecurity,
|
|
224
209
|
selectedSecuritySchemeUids,
|
|
225
210
|
// Merge path and operation level parameters
|
|
226
|
-
parameters: [
|
|
227
|
-
...(path?.parameters ?? []),
|
|
228
|
-
...(operation.parameters ?? []),
|
|
229
|
-
],
|
|
211
|
+
parameters: [...(path?.parameters ?? []), ...(operation.parameters ?? [])],
|
|
230
212
|
servers: [...pathServers, ...operationServers].map((s) => s.uid),
|
|
231
213
|
};
|
|
232
214
|
// Remove any examples from the request payload as they conflict with our examples property and are not valid
|
|
@@ -246,8 +228,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
246
228
|
[key]: s[key],
|
|
247
229
|
};
|
|
248
230
|
}
|
|
249
|
-
|
|
250
|
-
return s;
|
|
231
|
+
return s;
|
|
251
232
|
});
|
|
252
233
|
// Save parse the request
|
|
253
234
|
const request = schemaModel(requestPayload, requestSchema, false);
|
|
@@ -307,13 +288,17 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
307
288
|
// ---------------------------------------------------------------------------
|
|
308
289
|
// Generate Collection
|
|
309
290
|
// Grab the security requirements for this operation
|
|
310
|
-
const securityRequirements = (schema.security ?? [])
|
|
291
|
+
const securityRequirements = (schema.security ?? [])
|
|
292
|
+
.map((s) => {
|
|
311
293
|
const keys = Object.keys(s);
|
|
312
294
|
return keys.length > 1 ? keys : keys[0];
|
|
313
|
-
})
|
|
295
|
+
})
|
|
296
|
+
.filter(isDefined);
|
|
297
|
+
// Here we do not filter these as we let the preferredSecurityScheme override the requirements
|
|
298
|
+
const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat();
|
|
314
299
|
// Set the initially selected security scheme
|
|
315
|
-
const selectedSecuritySchemeUids = securityRequirements.length && setCollectionSecurity
|
|
316
|
-
? getSelectedSecuritySchemeUids(securityRequirements,
|
|
300
|
+
const selectedSecuritySchemeUids = (securityRequirements.length || preferredSecurityNames?.length) && setCollectionSecurity
|
|
301
|
+
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
317
302
|
: [];
|
|
318
303
|
const collection = collectionSchema.parse({
|
|
319
304
|
...schema,
|
|
@@ -377,7 +362,7 @@ function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
|
377
362
|
return parsedSchema;
|
|
378
363
|
}
|
|
379
364
|
catch (error) {
|
|
380
|
-
console.warn(
|
|
365
|
+
console.warn('Oops, that’s an invalid server configuration.');
|
|
381
366
|
console.warn('Server:', server);
|
|
382
367
|
console.warn('Error:', error);
|
|
383
368
|
// Return undefined to remove the server
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.107",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -127,18 +127,18 @@
|
|
|
127
127
|
"yaml": "^2.4.5",
|
|
128
128
|
"zod": "^3.23.8",
|
|
129
129
|
"@scalar/object-utils": "1.1.13",
|
|
130
|
-
"@scalar/
|
|
131
|
-
"@scalar/
|
|
132
|
-
"@scalar/
|
|
130
|
+
"@scalar/openapi-types": "0.1.8",
|
|
131
|
+
"@scalar/themes": "0.9.68",
|
|
132
|
+
"@scalar/types": "0.0.34"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
135
|
"type-fest": "^4.20.0",
|
|
136
136
|
"vite": "^5.4.10",
|
|
137
137
|
"vitest": "^1.6.0",
|
|
138
138
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
139
|
-
"@scalar/
|
|
140
|
-
"@scalar/openapi-types": "0.1.
|
|
141
|
-
"@scalar/
|
|
139
|
+
"@scalar/openapi-parser": "0.10.8",
|
|
140
|
+
"@scalar/openapi-types": "0.1.8",
|
|
141
|
+
"@scalar/build-tooling": "0.1.14"
|
|
142
142
|
},
|
|
143
143
|
"scripts": {
|
|
144
144
|
"build": "scalar-build-rollup",
|