@scalar/oas-utils 0.2.100 → 0.2.102
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 +23 -0
- package/dist/entities/shared/index.d.ts +1 -1
- package/dist/entities/shared/index.d.ts.map +1 -1
- package/dist/entities/shared/index.js +1 -1
- package/dist/entities/shared/utility.d.ts +3 -0
- package/dist/entities/shared/utility.d.ts.map +1 -1
- package/dist/entities/shared/utility.js +6 -1
- package/dist/entities/spec/collection.d.ts +6 -6
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +2 -2
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +5 -3
- package/dist/entities/spec/requests.d.ts +5 -3
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +2 -2
- package/dist/entities/spec/server.d.ts +29 -90
- package/dist/entities/spec/server.d.ts.map +1 -1
- package/dist/entities/spec/server.js +10 -5
- package/dist/migrations/data-version.d.ts +2 -1
- package/dist/migrations/data-version.d.ts.map +1 -1
- package/dist/migrations/data-version.js +2 -1
- package/dist/migrations/migrator.d.ts +2 -2
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +4 -0
- package/dist/migrations/v-2.4.0/types.generated.d.ts +363 -24
- package/dist/migrations/v-2.4.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/index.d.ts +3 -0
- package/dist/migrations/v-2.5.0/index.d.ts.map +1 -0
- package/dist/migrations/v-2.5.0/index.js +1 -0
- package/dist/migrations/v-2.5.0/migration.d.ts +5 -0
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -0
- package/dist/migrations/v-2.5.0/migration.js +46 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts +38 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -0
- package/dist/transforms/import-spec.d.ts +5 -0
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +31 -27
- package/dist/transforms/index.js +1 -1
- package/package.json +10 -5
|
@@ -4,12 +4,12 @@ import { schemaModel } from '../helpers/schema-model.js';
|
|
|
4
4
|
import { keysOf } from '@scalar/object-utils/arrays';
|
|
5
5
|
import { load, upgrade, dereference } from '@scalar/openapi-parser';
|
|
6
6
|
import { serverSchema } from '../entities/spec/server.js';
|
|
7
|
+
import { isDefined } from '../helpers/is-defined.js';
|
|
7
8
|
import { requestSchema } from '../entities/spec/requests.js';
|
|
8
9
|
import { tagSchema } from '../entities/spec/spec-objects.js';
|
|
9
10
|
import { createExampleFromRequest } from '../entities/spec/request-examples.js';
|
|
10
11
|
import { collectionSchema } from '../entities/spec/collection.js';
|
|
11
12
|
import { concatenateUrlAndPath } from '../helpers/concatenateUrlAndPath.js';
|
|
12
|
-
import { isDefined } from '../helpers/is-defined.js';
|
|
13
13
|
|
|
14
14
|
/** Takes a string or object and parses it into an openapi spec compliant schema */
|
|
15
15
|
const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
@@ -50,6 +50,17 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
50
50
|
errors: [...loadErrors, ...derefErrors],
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
+
/** Converts selected security requirements to uids */
|
|
54
|
+
const getSelectedSecuritySchemeUids = (securityRequirements, authentication, securitySchemeMap) => {
|
|
55
|
+
const name = authentication?.preferredSecurityScheme &&
|
|
56
|
+
securityRequirements.includes(authentication.preferredSecurityScheme)
|
|
57
|
+
? authentication.preferredSecurityScheme
|
|
58
|
+
: securityRequirements[0];
|
|
59
|
+
const uids = Array.isArray(name)
|
|
60
|
+
? name.map((k) => securitySchemeMap[k])
|
|
61
|
+
: securitySchemeMap[name];
|
|
62
|
+
return [uids];
|
|
63
|
+
};
|
|
53
64
|
/**
|
|
54
65
|
* Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
|
|
55
66
|
*
|
|
@@ -169,26 +180,18 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
169
180
|
operation.tags?.forEach((t) => tagNames.add(t));
|
|
170
181
|
// Remove security here and add it correctly below
|
|
171
182
|
const { security: operationSecurity, ...operationWithoutSecurity } = operation;
|
|
172
|
-
// Grab the security requirements for this operation
|
|
173
183
|
const securityRequirements = (operationSecurity ??
|
|
174
184
|
schema.security ??
|
|
175
|
-
[])
|
|
185
|
+
[])
|
|
186
|
+
.map((s) => {
|
|
176
187
|
const keys = Object.keys(s);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [];
|
|
181
|
-
});
|
|
182
|
-
let selectedSecuritySchemeUids = [];
|
|
188
|
+
return keys.length > 1 ? keys : keys[0];
|
|
189
|
+
})
|
|
190
|
+
.filter(isDefined);
|
|
183
191
|
// Set the initially selected security scheme
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
? authentication.preferredSecurityScheme
|
|
188
|
-
: securityRequirements[0];
|
|
189
|
-
const uid = securitySchemeMap[name];
|
|
190
|
-
selectedSecuritySchemeUids = [uid];
|
|
191
|
-
}
|
|
192
|
+
const selectedSecuritySchemeUids = securityRequirements.length && !setCollectionSecurity
|
|
193
|
+
? getSelectedSecuritySchemeUids(securityRequirements, authentication, securitySchemeMap)
|
|
194
|
+
: [];
|
|
192
195
|
const requestPayload = {
|
|
193
196
|
...operationWithoutSecurity,
|
|
194
197
|
method,
|
|
@@ -256,7 +259,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
256
259
|
});
|
|
257
260
|
// Add the request UIDs to the tag children (or collection root)
|
|
258
261
|
requests.forEach((r) => {
|
|
259
|
-
if (r.tags) {
|
|
262
|
+
if (r.tags?.length) {
|
|
260
263
|
r.tags.forEach((t) => {
|
|
261
264
|
tagMap[t].children.push(r.uid);
|
|
262
265
|
});
|
|
@@ -278,14 +281,15 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
278
281
|
});
|
|
279
282
|
// ---------------------------------------------------------------------------
|
|
280
283
|
// Generate Collection
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
284
|
+
// Grab the security requirements for this operation
|
|
285
|
+
const securityRequirements = (schema.security ?? []).map((s) => {
|
|
286
|
+
const keys = Object.keys(s);
|
|
287
|
+
return keys.length > 1 ? keys : keys[0];
|
|
288
|
+
});
|
|
289
|
+
// Set the initially selected security scheme
|
|
290
|
+
const selectedSecuritySchemeUids = securityRequirements.length && setCollectionSecurity
|
|
291
|
+
? getSelectedSecuritySchemeUids(securityRequirements, authentication, securitySchemeMap)
|
|
292
|
+
: [];
|
|
289
293
|
const collection = collectionSchema.parse({
|
|
290
294
|
...schema,
|
|
291
295
|
watchMode,
|
|
@@ -357,4 +361,4 @@ function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
|
357
361
|
.filter(isDefined);
|
|
358
362
|
}
|
|
359
363
|
|
|
360
|
-
export { getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema };
|
|
364
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema };
|
package/dist/transforms/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
|
1
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
|
2
2
|
export { exportSpecFromWorkspace } from './export-spec.js';
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.102",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"types": "./dist/migrations/index.d.ts",
|
|
39
39
|
"default": "./dist/migrations/index.js"
|
|
40
40
|
},
|
|
41
|
+
"./migrations/v-2.5.0": {
|
|
42
|
+
"import": "./dist/migrations/v-2.5.0/index.js",
|
|
43
|
+
"types": "./dist/migrations/v-2.5.0/index.d.ts",
|
|
44
|
+
"default": "./dist/migrations/v-2.5.0/index.js"
|
|
45
|
+
},
|
|
41
46
|
"./migrations/v-2.4.0": {
|
|
42
47
|
"import": "./dist/migrations/v-2.4.0/index.js",
|
|
43
48
|
"types": "./dist/migrations/v-2.4.0/index.d.ts",
|
|
@@ -122,9 +127,9 @@
|
|
|
122
127
|
"yaml": "^2.4.5",
|
|
123
128
|
"zod": "^3.23.8",
|
|
124
129
|
"@scalar/object-utils": "1.1.12",
|
|
125
|
-
"@scalar/themes": "0.9.
|
|
126
|
-
"@scalar/types": "0.
|
|
127
|
-
"@scalar/
|
|
130
|
+
"@scalar/themes": "0.9.64",
|
|
131
|
+
"@scalar/openapi-types": "0.1.7",
|
|
132
|
+
"@scalar/types": "0.0.30"
|
|
128
133
|
},
|
|
129
134
|
"devDependencies": {
|
|
130
135
|
"type-fest": "^4.20.0",
|
|
@@ -133,7 +138,7 @@
|
|
|
133
138
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
134
139
|
"@scalar/build-tooling": "0.1.12",
|
|
135
140
|
"@scalar/openapi-parser": "0.10.4",
|
|
136
|
-
"@scalar/openapi-types": "0.1.
|
|
141
|
+
"@scalar/openapi-types": "0.1.7"
|
|
137
142
|
},
|
|
138
143
|
"scripts": {
|
|
139
144
|
"build": "scalar-build-rollup",
|