@scalar/oas-utils 0.2.140 → 0.2.142
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 +18 -0
- package/dist/entities/cookie/cookie.js +14 -13
- package/dist/entities/cookie/cookie.js.map +7 -0
- package/dist/entities/cookie/index.d.ts +1 -1
- package/dist/entities/cookie/index.d.ts.map +1 -1
- package/dist/entities/cookie/index.js +5 -1
- package/dist/entities/cookie/index.js.map +7 -0
- package/dist/entities/environment/environment.js +10 -9
- package/dist/entities/environment/environment.js.map +7 -0
- package/dist/entities/environment/index.d.ts +1 -1
- package/dist/entities/environment/index.d.ts.map +1 -1
- package/dist/entities/environment/index.js +5 -1
- package/dist/entities/environment/index.js.map +7 -0
- package/dist/entities/hotkeys/hotkeys.js +109 -116
- package/dist/entities/hotkeys/hotkeys.js.map +7 -0
- package/dist/entities/hotkeys/index.d.ts +1 -1
- package/dist/entities/hotkeys/index.d.ts.map +1 -1
- package/dist/entities/hotkeys/index.js +6 -1
- package/dist/entities/hotkeys/index.js.map +7 -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 +7 -1
- package/dist/entities/shared/index.js.map +7 -0
- package/dist/entities/shared/utility.js +9 -12
- package/dist/entities/shared/utility.js.map +7 -0
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +91 -94
- package/dist/entities/spec/collection.js.map +7 -0
- package/dist/entities/spec/index.d.ts +8 -8
- package/dist/entities/spec/index.d.ts.map +1 -1
- package/dist/entities/spec/index.js +59 -9
- package/dist/entities/spec/index.js.map +7 -0
- package/dist/entities/spec/operation.d.ts +1 -1
- package/dist/entities/spec/operation.d.ts.map +1 -1
- package/dist/entities/spec/operation.js +5 -8
- package/dist/entities/spec/operation.js.map +7 -0
- package/dist/entities/spec/operation.test.js +43 -0
- package/dist/entities/spec/operation.test.js.map +7 -0
- package/dist/entities/spec/parameters.d.ts +1 -1
- package/dist/entities/spec/parameters.d.ts.map +1 -1
- package/dist/entities/spec/parameters.js +40 -38
- package/dist/entities/spec/parameters.js.map +7 -0
- package/dist/entities/spec/parameters.test.js +71 -0
- package/dist/entities/spec/parameters.test.js.map +7 -0
- package/dist/entities/spec/request-example.test.js +637 -0
- package/dist/entities/spec/request-example.test.js.map +7 -0
- package/dist/entities/spec/request-examples.d.ts +3 -3
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +323 -338
- package/dist/entities/spec/request-examples.js.map +7 -0
- package/dist/entities/spec/requests.d.ts +6 -8
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +80 -101
- package/dist/entities/spec/requests.js.map +7 -0
- package/dist/entities/spec/server.js +47 -63
- package/dist/entities/spec/server.js.map +7 -0
- package/dist/entities/spec/server.test.js +120 -0
- package/dist/entities/spec/server.test.js.map +7 -0
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +77 -121
- package/dist/entities/spec/spec-objects.js.map +7 -0
- package/dist/entities/spec/spec-objects.test.js +205 -0
- package/dist/entities/spec/spec-objects.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.js +21 -18
- package/dist/entities/spec/x-scalar-environments.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.test.js +11 -0
- package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.js +8 -6
- package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
- package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
- package/dist/entities/workspace/index.d.ts +1 -1
- package/dist/entities/workspace/index.d.ts.map +1 -1
- package/dist/entities/workspace/index.js +7 -1
- package/dist/entities/workspace/index.js.map +7 -0
- package/dist/entities/workspace/workspace.js +46 -50
- package/dist/entities/workspace/workspace.js.map +7 -0
- package/dist/helpers/create-hash.js +15 -18
- package/dist/helpers/create-hash.js.map +7 -0
- package/dist/helpers/ensure-protocol.js +9 -10
- package/dist/helpers/ensure-protocol.js.map +7 -0
- package/dist/helpers/ensure-protocol.test.js +70 -0
- package/dist/helpers/ensure-protocol.test.js.map +7 -0
- package/dist/helpers/fetch-document.js +24 -32
- package/dist/helpers/fetch-document.js.map +7 -0
- package/dist/helpers/fetch-document.test.js +63 -0
- package/dist/helpers/fetch-document.test.js.map +7 -0
- package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
- package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
- package/dist/helpers/find-variables.d.ts +1 -1
- package/dist/helpers/find-variables.d.ts.map +1 -1
- package/dist/helpers/find-variables.js +6 -8
- package/dist/helpers/find-variables.js.map +7 -0
- package/dist/helpers/find-variables.test.js +20 -0
- package/dist/helpers/find-variables.test.js.map +7 -0
- package/dist/helpers/http-methods.d.ts +1 -1
- package/dist/helpers/http-methods.d.ts.map +1 -1
- package/dist/helpers/http-methods.js +60 -66
- package/dist/helpers/http-methods.js.map +7 -0
- package/dist/helpers/http-status-codes.js +319 -317
- package/dist/helpers/http-status-codes.js.map +7 -0
- package/dist/helpers/index.d.ts +27 -27
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +73 -27
- package/dist/helpers/index.js.map +7 -0
- package/dist/helpers/is-defined.js +5 -14
- package/dist/helpers/is-defined.js.map +7 -0
- package/dist/helpers/is-defined.test.js +37 -0
- package/dist/helpers/is-defined.test.js.map +7 -0
- package/dist/helpers/is-local-url.js +11 -16
- package/dist/helpers/is-local-url.js.map +7 -0
- package/dist/helpers/is-local-url.test.js +40 -0
- package/dist/helpers/is-local-url.test.js.map +7 -0
- package/dist/helpers/is-valid-url.js +9 -18
- package/dist/helpers/is-valid-url.js.map +7 -0
- package/dist/helpers/is-valid-url.test.js +17 -0
- package/dist/helpers/is-valid-url.test.js.map +7 -0
- package/dist/helpers/iterate-title.js +11 -15
- package/dist/helpers/iterate-title.js.map +7 -0
- package/dist/helpers/json2xml.js +40 -47
- package/dist/helpers/json2xml.js.map +7 -0
- package/dist/helpers/json2xml.test.js +19 -0
- package/dist/helpers/json2xml.test.js.map +7 -0
- package/dist/helpers/local-storage.js +13 -15
- package/dist/helpers/local-storage.js.map +7 -0
- package/dist/helpers/make-url-absolute.js +11 -17
- package/dist/helpers/make-url-absolute.js.map +7 -0
- package/dist/helpers/make-url-absolute.test.js +61 -0
- package/dist/helpers/make-url-absolute.test.js.map +7 -0
- package/dist/helpers/merge-urls.js +50 -75
- package/dist/helpers/merge-urls.js.map +7 -0
- package/dist/helpers/merge-urls.test.js +339 -0
- package/dist/helpers/merge-urls.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.js +21 -31
- package/dist/helpers/normalize-mime-type-object.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.test.js +53 -0
- package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type.js +8 -18
- package/dist/helpers/normalize-mime-type.js.map +7 -0
- package/dist/helpers/normalize-mime-type.test.js +33 -0
- package/dist/helpers/normalize-mime-type.test.js.map +7 -0
- package/dist/helpers/object.js +12 -18
- package/dist/helpers/object.js.map +7 -0
- package/dist/helpers/omit-undefined-values.js +17 -19
- package/dist/helpers/omit-undefined-values.js.map +7 -0
- package/dist/helpers/omit-undefined-values.test.js +89 -0
- package/dist/helpers/omit-undefined-values.test.js.map +7 -0
- package/dist/helpers/parse.js +71 -83
- package/dist/helpers/parse.js.map +7 -0
- package/dist/helpers/parse.test.js +45 -0
- package/dist/helpers/parse.test.js.map +7 -0
- package/dist/helpers/pretty-print-json.js +31 -35
- package/dist/helpers/pretty-print-json.js.map +7 -0
- package/dist/helpers/pretty-print-json.test.js +28 -0
- package/dist/helpers/pretty-print-json.test.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.js +46 -83
- package/dist/helpers/redirect-to-proxy.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.test.js +54 -0
- package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
- package/dist/helpers/regex-helpers.js +11 -9
- package/dist/helpers/regex-helpers.js.map +7 -0
- package/dist/helpers/regex-helpers.test.js +154 -0
- package/dist/helpers/regex-helpers.test.js.map +7 -0
- package/dist/helpers/replace-variables.js +13 -16
- package/dist/helpers/replace-variables.js.map +7 -0
- package/dist/helpers/replace-variables.test.js +30 -0
- package/dist/helpers/replace-variables.test.js.map +7 -0
- package/dist/helpers/schema-model.js +15 -14
- package/dist/helpers/schema-model.js.map +7 -0
- package/dist/helpers/security/get-schemes.d.ts +1 -1
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/dist/helpers/security/get-schemes.js +7 -9
- package/dist/helpers/security/get-schemes.js.map +7 -0
- package/dist/helpers/security/get-schemes.test.js +71 -0
- package/dist/helpers/security/get-schemes.test.js.map +7 -0
- package/dist/helpers/security/has-token.js +18 -19
- package/dist/helpers/security/has-token.js.map +7 -0
- package/dist/helpers/security/has-token.test.js +157 -0
- package/dist/helpers/security/has-token.test.js.map +7 -0
- package/dist/helpers/security/index.d.ts +2 -2
- package/dist/helpers/security/index.d.ts.map +1 -1
- package/dist/helpers/security/index.js +7 -2
- package/dist/helpers/security/index.js.map +7 -0
- package/dist/helpers/should-ignore-entity.d.ts +2 -2
- package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
- package/dist/helpers/should-ignore-entity.js +5 -6
- package/dist/helpers/should-ignore-entity.js.map +7 -0
- package/dist/helpers/ssr-state.js +6 -6
- package/dist/helpers/ssr-state.js.map +7 -0
- package/dist/helpers/string.js +6 -18
- package/dist/helpers/string.js.map +7 -0
- package/dist/migrations/data-version.js +7 -17
- package/dist/migrations/data-version.js.map +7 -0
- package/dist/migrations/generate-types.js +56 -0
- package/dist/migrations/generate-types.js.map +7 -0
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +10 -3
- package/dist/migrations/index.js.map +7 -0
- package/dist/migrations/local-storage.d.ts +1 -1
- package/dist/migrations/local-storage.d.ts.map +1 -1
- package/dist/migrations/local-storage.js +27 -32
- package/dist/migrations/local-storage.js.map +7 -0
- package/dist/migrations/migrator.d.ts +1 -1
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +51 -58
- package/dist/migrations/migrator.js.map +7 -0
- package/dist/migrations/semver.js +23 -25
- package/dist/migrations/semver.js.map +7 -0
- package/dist/migrations/semver.test.js +21 -0
- package/dist/migrations/semver.test.js.map +7 -0
- package/dist/migrations/v-0.0.0/types.generated.js +1 -0
- package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.js +256 -273
- package/dist/migrations/v-2.1.0/migration.js.map +7 -0
- package/dist/migrations/v-2.1.0/types.generated.js +1 -0
- package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.js +95 -100
- package/dist/migrations/v-2.2.0/migration.js.map +7 -0
- package/dist/migrations/v-2.2.0/types.generated.js +1 -0
- package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.3.0/migration.js +47 -46
- package/dist/migrations/v-2.3.0/migration.js.map +7 -0
- package/dist/migrations/v-2.3.0/types.generated.js +1 -0
- package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.4.0/migration.js +24 -26
- package/dist/migrations/v-2.4.0/migration.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.test.js +90 -0
- package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.4.0/types.generated.js +1 -0
- package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +135 -119
- package/dist/migrations/v-2.5.0/migration.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.test.js +108 -0
- package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/types.generated.js +1 -0
- package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.js +206 -268
- package/dist/spec-getters/get-example-from-schema.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
- package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.js +22 -42
- package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.js +110 -162
- package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
- package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
- package/dist/spec-getters/get-server-variable-examples.js +12 -11
- package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
- package/dist/spec-getters/index.d.ts +4 -4
- package/dist/spec-getters/index.d.ts.map +1 -1
- package/dist/spec-getters/index.js +11 -4
- package/dist/spec-getters/index.js.map +7 -0
- package/dist/transforms/import-spec.d.ts +6 -6
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +313 -425
- package/dist/transforms/import-spec.js.map +7 -0
- package/dist/transforms/import-spec.test.js +1124 -0
- package/dist/transforms/import-spec.test.js.map +7 -0
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +13 -1
- package/dist/transforms/index.js.map +7 -0
- package/package.json +10 -11
|
@@ -1,451 +1,339 @@
|
|
|
1
|
-
import { keysOf } from
|
|
2
|
-
import { load, upgrade
|
|
3
|
-
import { collectionSchema } from
|
|
4
|
-
import { createExampleFromRequest } from
|
|
5
|
-
import { requestSchema } from
|
|
6
|
-
import { serverSchema } from
|
|
7
|
-
import { tagSchema } from
|
|
8
|
-
import { isHttpMethod } from
|
|
9
|
-
import { isDefined } from
|
|
10
|
-
import { combineUrlAndPath } from
|
|
11
|
-
import { schemaModel } from
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { keysOf } from "@scalar/object-utils/arrays";
|
|
2
|
+
import { dereference, load, upgrade } from "@scalar/openapi-parser";
|
|
3
|
+
import { collectionSchema } from "../entities/spec/collection.js";
|
|
4
|
+
import { createExampleFromRequest } from "../entities/spec/request-examples.js";
|
|
5
|
+
import { requestSchema } from "../entities/spec/requests.js";
|
|
6
|
+
import { serverSchema } from "../entities/spec/server.js";
|
|
7
|
+
import { tagSchema } from "../entities/spec/spec-objects.js";
|
|
8
|
+
import { isHttpMethod } from "../helpers/http-methods.js";
|
|
9
|
+
import { isDefined } from "../helpers/is-defined.js";
|
|
10
|
+
import { combineUrlAndPath } from "../helpers/merge-urls.js";
|
|
11
|
+
import { schemaModel } from "../helpers/schema-model.js";
|
|
12
|
+
import {
|
|
13
|
+
securitySchemeSchema
|
|
14
|
+
} from "@scalar/types/entities";
|
|
15
15
|
const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
schema: {},
|
|
20
|
-
errors: [],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
let filesystem = spec;
|
|
24
|
-
let loadErrors = [];
|
|
25
|
-
if (shouldLoad) {
|
|
26
|
-
// TODO: Plugins for URLs and files with the proxy is missing here.
|
|
27
|
-
// @see packages/api-reference/src/helpers/parse.ts
|
|
28
|
-
const resp = await load(spec).catch((e) => ({
|
|
29
|
-
errors: [
|
|
30
|
-
{
|
|
31
|
-
code: e.code,
|
|
32
|
-
message: e.message,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
filesystem: [],
|
|
36
|
-
}));
|
|
37
|
-
filesystem = resp.filesystem;
|
|
38
|
-
loadErrors = resp.errors ?? [];
|
|
39
|
-
}
|
|
40
|
-
const { specification } = upgrade(filesystem);
|
|
41
|
-
const { schema, errors: derefErrors = [] } = await dereference(specification);
|
|
42
|
-
if (!schema) {
|
|
43
|
-
console.warn('[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined');
|
|
44
|
-
}
|
|
16
|
+
if (spec === null || typeof spec === "string" && spec.trim() === "") {
|
|
17
|
+
console.warn("[@scalar/oas-utils] Empty OpenAPI document provided.");
|
|
45
18
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* TODO: remove this once the parser is fixed
|
|
49
|
-
*/
|
|
50
|
-
schema: (Array.isArray(schema) ? {} : schema),
|
|
51
|
-
errors: [...loadErrors, ...derefErrors],
|
|
19
|
+
schema: {},
|
|
20
|
+
errors: []
|
|
52
21
|
};
|
|
22
|
+
}
|
|
23
|
+
let filesystem = spec;
|
|
24
|
+
let loadErrors = [];
|
|
25
|
+
if (shouldLoad) {
|
|
26
|
+
const resp = await load(spec).catch((e) => ({
|
|
27
|
+
errors: [
|
|
28
|
+
{
|
|
29
|
+
code: e.code,
|
|
30
|
+
message: e.message
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
filesystem: []
|
|
34
|
+
}));
|
|
35
|
+
filesystem = resp.filesystem;
|
|
36
|
+
loadErrors = resp.errors ?? [];
|
|
37
|
+
}
|
|
38
|
+
const { specification } = upgrade(filesystem);
|
|
39
|
+
const { schema, errors: derefErrors = [] } = await dereference(specification);
|
|
40
|
+
if (!schema) {
|
|
41
|
+
console.warn("[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
/**
|
|
45
|
+
* Temporary fix for the parser returning an empty array
|
|
46
|
+
* TODO: remove this once the parser is fixed
|
|
47
|
+
*/
|
|
48
|
+
schema: Array.isArray(schema) ? {} : schema,
|
|
49
|
+
errors: [...loadErrors, ...derefErrors]
|
|
50
|
+
};
|
|
53
51
|
};
|
|
54
|
-
/** Converts selected security requirements to uids */
|
|
55
52
|
const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNames = [], securitySchemeMap) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.filter(isDefined);
|
|
62
|
-
return uids;
|
|
53
|
+
const names = securityRequirements[0] && !preferredSecurityNames.length ? [securityRequirements[0]] : preferredSecurityNames;
|
|
54
|
+
const uids = names.map(
|
|
55
|
+
(name) => Array.isArray(name) ? name.map((k) => securitySchemeMap[k]).filter(isDefined) : securitySchemeMap[name]
|
|
56
|
+
).filter(isDefined);
|
|
57
|
+
return uids;
|
|
63
58
|
};
|
|
64
|
-
/** Create a "uid" from a slug */
|
|
65
59
|
const getSlugUid = (slug) => `slug-uid-${slug}`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
async function importSpecToWorkspace(spec, {
|
|
61
|
+
authentication,
|
|
62
|
+
baseServerURL,
|
|
63
|
+
documentUrl,
|
|
64
|
+
servers: configuredServers,
|
|
65
|
+
useCollectionSecurity = false,
|
|
66
|
+
slug,
|
|
67
|
+
shouldLoad,
|
|
68
|
+
watchMode = false
|
|
69
|
+
} = {}) {
|
|
70
|
+
const { schema, errors } = await parseSchema(spec, { shouldLoad });
|
|
71
|
+
const importWarnings = [...errors.map((e) => e.message)];
|
|
72
|
+
if (!schema) {
|
|
73
|
+
return { importWarnings, error: true, collection: void 0 };
|
|
74
|
+
}
|
|
75
|
+
const start = performance.now();
|
|
76
|
+
const requests = [];
|
|
77
|
+
const collectionServers = getServersFromOpenApiDocument(configuredServers || schema.servers, {
|
|
78
|
+
baseServerURL
|
|
79
|
+
});
|
|
80
|
+
const operationServers = [];
|
|
81
|
+
if (!collectionServers.length) {
|
|
82
|
+
const fallbackUrl = getFallbackUrl();
|
|
83
|
+
if (fallbackUrl) {
|
|
84
|
+
collectionServers.push(serverSchema.parse({ url: fallbackUrl }));
|
|
84
85
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
}
|
|
87
|
+
const tagNames = /* @__PURE__ */ new Set();
|
|
88
|
+
const security = schema.components?.securitySchemes ?? schema?.securityDefinitions ?? {};
|
|
89
|
+
if (authentication?.oAuth2 || authentication?.apiKey || authentication?.http) {
|
|
90
|
+
console.warn(
|
|
91
|
+
`DEPRECATION WARNING: It looks like you're using legacy authentication config. Please migrate to use the updated config. See https://github.com/scalar/scalar/blob/main/documentation/configuration.md#authentication-partial This will be removed in a future version.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const securitySchemes = Object.entries(security).map?.(([nameKey, _scheme]) => {
|
|
95
|
+
const payload = {
|
|
96
|
+
..._scheme,
|
|
97
|
+
// Add the new auth config overrides, we keep the old code below for backwards compatibility
|
|
98
|
+
...authentication?.securitySchemes?.[nameKey] ?? {},
|
|
99
|
+
nameKey
|
|
100
|
+
};
|
|
101
|
+
if (payload.type === "oauth2" && payload.flows) {
|
|
102
|
+
const flowKeys = Object.keys(payload.flows);
|
|
103
|
+
flowKeys.forEach((key) => {
|
|
104
|
+
if (!payload.flows?.[key] || _scheme.type !== "oauth2") {
|
|
105
|
+
return;
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*/
|
|
106
|
-
const tagNames = new Set();
|
|
107
|
-
// ---------------------------------------------------------------------------
|
|
108
|
-
// SECURITY HANDLING
|
|
109
|
-
const security = schema.components?.securitySchemes ?? schema?.securityDefinitions ?? {};
|
|
110
|
-
// @ts-expect-error - Toss out a deprecated warning for the old authentication state
|
|
111
|
-
if (authentication?.oAuth2 || authentication?.apiKey || authentication?.http) {
|
|
112
|
-
console.warn(`DEPRECATION WARNING: It looks like you're using legacy authentication config. Please migrate to use the updated config. See https://github.com/scalar/scalar/blob/main/documentation/configuration.md#authentication-partial This will be removed in a future version.`);
|
|
113
|
-
}
|
|
114
|
-
const securitySchemes = Object.entries(security)
|
|
115
|
-
.map?.(([nameKey, _scheme]) => {
|
|
116
|
-
// Apply any transforms we need before parsing
|
|
117
|
-
const payload = {
|
|
118
|
-
..._scheme,
|
|
119
|
-
// Add the new auth config overrides, we keep the old code below for backwards compatibility
|
|
120
|
-
...(authentication?.securitySchemes?.[nameKey] ?? {}),
|
|
121
|
-
nameKey,
|
|
107
|
+
const authFlow = authentication?.securitySchemes?.[nameKey]?.flows?.[key] ?? {};
|
|
108
|
+
payload.flows[key] = {
|
|
109
|
+
..._scheme.flows?.[key] ?? {},
|
|
110
|
+
...authFlow
|
|
122
111
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Prefill values from authorization config - old deprecated config
|
|
140
|
-
// @ts-expect-error - deprecated
|
|
141
|
-
if (authentication?.oAuth2) {
|
|
142
|
-
// @ts-expect-error - deprecated
|
|
143
|
-
if (authentication.oAuth2.accessToken) {
|
|
144
|
-
// @ts-expect-error - deprecated
|
|
145
|
-
flow.token = authentication.oAuth2.accessToken;
|
|
146
|
-
}
|
|
147
|
-
// @ts-expect-error - deprecated
|
|
148
|
-
if (authentication.oAuth2.clientId) {
|
|
149
|
-
// @ts-expect-error - deprecated
|
|
150
|
-
flow['x-scalar-client-id'] = authentication.oAuth2.clientId;
|
|
151
|
-
}
|
|
152
|
-
// @ts-expect-error - deprecated
|
|
153
|
-
if (authentication.oAuth2.scopes) {
|
|
154
|
-
// @ts-expect-error - deprecated
|
|
155
|
-
flow.selectedScopes = authentication.oAuth2.scopes;
|
|
156
|
-
}
|
|
157
|
-
if (flow.type === 'password') {
|
|
158
|
-
// @ts-expect-error - deprecated
|
|
159
|
-
flow.username = authentication.oAuth2.username;
|
|
160
|
-
// @ts-expect-error - deprecated
|
|
161
|
-
flow.password = authentication.oAuth2.password;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// Convert scopes to an object
|
|
165
|
-
if (Array.isArray(flow.scopes)) {
|
|
166
|
-
flow.scopes = flow.scopes.reduce((prev, s) => ({ ...prev, [s]: '' }), {});
|
|
167
|
-
}
|
|
168
|
-
// Handle x-defaultClientId
|
|
169
|
-
if (flow['x-defaultClientId']) {
|
|
170
|
-
flow['x-scalar-client-id'] = flow['x-defaultClientId'];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
112
|
+
const flow = payload.flows[key];
|
|
113
|
+
flow.type = key;
|
|
114
|
+
if (authentication?.oAuth2) {
|
|
115
|
+
if (authentication.oAuth2.accessToken) {
|
|
116
|
+
flow.token = authentication.oAuth2.accessToken;
|
|
117
|
+
}
|
|
118
|
+
if (authentication.oAuth2.clientId) {
|
|
119
|
+
flow["x-scalar-client-id"] = authentication.oAuth2.clientId;
|
|
120
|
+
}
|
|
121
|
+
if (authentication.oAuth2.scopes) {
|
|
122
|
+
flow.selectedScopes = authentication.oAuth2.scopes;
|
|
123
|
+
}
|
|
124
|
+
if (flow.type === "password") {
|
|
125
|
+
flow.username = authentication.oAuth2.username;
|
|
126
|
+
flow.password = authentication.oAuth2.password;
|
|
127
|
+
}
|
|
173
128
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// ApiKey
|
|
177
|
-
// @ts-expect-error - deprecated
|
|
178
|
-
if (payload.type === 'apiKey' && authentication.apiKey?.token) {
|
|
179
|
-
// @ts-expect-error - deprecated
|
|
180
|
-
payload.value = authentication.apiKey.token;
|
|
181
|
-
}
|
|
182
|
-
// HTTP
|
|
183
|
-
else if (payload.type === 'http') {
|
|
184
|
-
// @ts-expect-error - deprecated
|
|
185
|
-
if (payload.scheme === 'basic' && authentication.http?.basic) {
|
|
186
|
-
// @ts-expect-error - deprecated
|
|
187
|
-
payload.username = authentication.http.basic.username ?? '';
|
|
188
|
-
// @ts-expect-error - deprecated
|
|
189
|
-
payload.password = authentication.http.basic.password ?? '';
|
|
190
|
-
}
|
|
191
|
-
// Bearer
|
|
192
|
-
// @ts-expect-error - deprecated
|
|
193
|
-
else if (payload.scheme === 'bearer' && authentication.http?.bearer?.token) {
|
|
194
|
-
// @ts-expect-error - deprecated
|
|
195
|
-
payload.token = authentication.http.bearer.token ?? '';
|
|
196
|
-
}
|
|
197
|
-
}
|
|
129
|
+
if (Array.isArray(flow.scopes)) {
|
|
130
|
+
flow.scopes = flow.scopes.reduce((prev, s) => ({ ...prev, [s]: "" }), {});
|
|
198
131
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
importWarnings.push(`Security scheme ${nameKey} is invalid.`);
|
|
132
|
+
if (flow["x-defaultClientId"]) {
|
|
133
|
+
flow["x-scalar-client-id"] = flow["x-defaultClientId"];
|
|
202
134
|
}
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
keysOf(schema.paths ?? {}).forEach((pathString) => {
|
|
214
|
-
const path = schema?.paths?.[pathString];
|
|
215
|
-
if (!path) {
|
|
216
|
-
return;
|
|
135
|
+
});
|
|
136
|
+
} else if (authentication) {
|
|
137
|
+
if (payload.type === "apiKey" && authentication.apiKey?.token) {
|
|
138
|
+
payload.value = authentication.apiKey.token;
|
|
139
|
+
} else if (payload.type === "http") {
|
|
140
|
+
if (payload.scheme === "basic" && authentication.http?.basic) {
|
|
141
|
+
payload.username = authentication.http.basic.username ?? "";
|
|
142
|
+
payload.password = authentication.http.basic.password ?? "";
|
|
143
|
+
} else if (payload.scheme === "bearer" && authentication.http?.bearer?.token) {
|
|
144
|
+
payload.token = authentication.http.bearer.token ?? "";
|
|
217
145
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const scheme = schemaModel(payload, securitySchemeSchema, false);
|
|
149
|
+
if (!scheme) {
|
|
150
|
+
importWarnings.push(`Security scheme ${nameKey} is invalid.`);
|
|
151
|
+
}
|
|
152
|
+
return scheme;
|
|
153
|
+
}).filter((v) => !!v);
|
|
154
|
+
const securitySchemeMap = {};
|
|
155
|
+
securitySchemes.forEach((s) => {
|
|
156
|
+
securitySchemeMap[s.nameKey] = s.uid;
|
|
157
|
+
});
|
|
158
|
+
keysOf(schema.paths ?? {}).forEach((pathString) => {
|
|
159
|
+
const path = schema?.paths?.[pathString];
|
|
160
|
+
if (!path) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pathServers = serverSchema.array().parse(path.servers ?? []);
|
|
164
|
+
for (const server of pathServers) {
|
|
165
|
+
collectionServers.push(server);
|
|
166
|
+
}
|
|
167
|
+
const methods = Object.keys(path).filter(isHttpMethod);
|
|
168
|
+
methods.forEach((method) => {
|
|
169
|
+
const operation = path[method];
|
|
170
|
+
const operationLevelServers = serverSchema.array().parse(operation.servers ?? []);
|
|
171
|
+
for (const server of operationLevelServers) {
|
|
172
|
+
operationServers.push(server);
|
|
173
|
+
}
|
|
174
|
+
operation.tags?.forEach((t) => tagNames.add(t));
|
|
175
|
+
const { security: operationSecurity, ...operationWithoutSecurity } = operation;
|
|
176
|
+
const securityRequirements2 = (operationSecurity ?? schema.security ?? []).map((s) => {
|
|
177
|
+
const keys = Object.keys(s);
|
|
178
|
+
return keys.length > 1 ? keys : keys[0];
|
|
179
|
+
}).filter(isDefined);
|
|
180
|
+
const preferredSecurityNames2 = [authentication?.preferredSecurityScheme ?? []].flat().filter((name) => {
|
|
181
|
+
if (Array.isArray(name)) {
|
|
182
|
+
return securityRequirements2.some(
|
|
183
|
+
(r) => Array.isArray(r) && r.length === name.length && r.every((v, i) => v === name[i])
|
|
184
|
+
);
|
|
222
185
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
251
|
-
// Set the initially selected security scheme
|
|
252
|
-
const selectedSecuritySchemeUids = securityRequirements.length && !useCollectionSecurity
|
|
253
|
-
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
254
|
-
: [];
|
|
255
|
-
const requestPayload = {
|
|
256
|
-
...operationWithoutSecurity,
|
|
257
|
-
method,
|
|
258
|
-
path: pathString,
|
|
259
|
-
security: operationSecurity,
|
|
260
|
-
selectedServerUid: operationLevelServers?.[0]?.uid,
|
|
261
|
-
selectedSecuritySchemeUids,
|
|
262
|
-
// Merge path and operation level parameters
|
|
263
|
-
parameters: [...(path?.parameters ?? []), ...(operation.parameters ?? [])],
|
|
264
|
-
servers: [...pathServers, ...operationLevelServers].map((s) => s.uid),
|
|
265
|
-
};
|
|
266
|
-
// Remove any examples from the request payload as they conflict with our examples property and are not valid
|
|
267
|
-
if (requestPayload.examples) {
|
|
268
|
-
console.warn('[@scalar/api-client] operation.examples is not a valid openapi property');
|
|
269
|
-
delete requestPayload.examples;
|
|
270
|
-
}
|
|
271
|
-
// Add list of UIDs to associate security schemes
|
|
272
|
-
// As per the spec if there is operation level security we ignore the top level requirements
|
|
273
|
-
if (operationSecurity?.length) {
|
|
274
|
-
requestPayload.security = operationSecurity.map((s) => {
|
|
275
|
-
const keys = Object.keys(s);
|
|
276
|
-
// Handle the case of {} for optional
|
|
277
|
-
if (keys.length) {
|
|
278
|
-
const [key] = Object.keys(s);
|
|
279
|
-
if (key) {
|
|
280
|
-
return {
|
|
281
|
-
[key]: s[key],
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return s;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
// Save parse the request
|
|
289
|
-
const request = schemaModel(requestPayload, requestSchema, false);
|
|
290
|
-
if (!request) {
|
|
291
|
-
importWarnings.push(`${method} Request at ${path} is invalid.`);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
requests.push(request);
|
|
186
|
+
return securityRequirements2.includes(name);
|
|
187
|
+
});
|
|
188
|
+
const selectedSecuritySchemeUids2 = securityRequirements2.length && !useCollectionSecurity ? getSelectedSecuritySchemeUids(securityRequirements2, preferredSecurityNames2, securitySchemeMap) : [];
|
|
189
|
+
const requestPayload = {
|
|
190
|
+
...operationWithoutSecurity,
|
|
191
|
+
method,
|
|
192
|
+
path: pathString,
|
|
193
|
+
security: operationSecurity,
|
|
194
|
+
selectedServerUid: operationLevelServers?.[0]?.uid,
|
|
195
|
+
selectedSecuritySchemeUids: selectedSecuritySchemeUids2,
|
|
196
|
+
// Merge path and operation level parameters
|
|
197
|
+
parameters: [...path?.parameters ?? [], ...operation.parameters ?? []],
|
|
198
|
+
servers: [...pathServers, ...operationLevelServers].map((s) => s.uid)
|
|
199
|
+
};
|
|
200
|
+
if (requestPayload.examples) {
|
|
201
|
+
console.warn("[@scalar/api-client] operation.examples is not a valid openapi property");
|
|
202
|
+
delete requestPayload.examples;
|
|
203
|
+
}
|
|
204
|
+
if (operationSecurity?.length) {
|
|
205
|
+
requestPayload.security = operationSecurity.map((s) => {
|
|
206
|
+
const keys = Object.keys(s);
|
|
207
|
+
if (keys.length) {
|
|
208
|
+
const [key] = Object.keys(s);
|
|
209
|
+
if (key) {
|
|
210
|
+
return {
|
|
211
|
+
[key]: s[key]
|
|
212
|
+
};
|
|
295
213
|
}
|
|
214
|
+
}
|
|
215
|
+
return s;
|
|
296
216
|
});
|
|
217
|
+
}
|
|
218
|
+
const request = schemaModel(requestPayload, requestSchema, false);
|
|
219
|
+
if (!request) {
|
|
220
|
+
importWarnings.push(`${method} Request at ${path} is invalid.`);
|
|
221
|
+
} else {
|
|
222
|
+
requests.push(request);
|
|
223
|
+
}
|
|
297
224
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
225
|
+
});
|
|
226
|
+
const tags = schemaModel(schema?.tags ?? [], tagSchema.array(), false) ?? [];
|
|
227
|
+
tags.forEach((t) => tagNames.delete(t.name));
|
|
228
|
+
tagNames.forEach((name) => name && tags.push(tagSchema.parse({ name })));
|
|
229
|
+
const tagMap = {};
|
|
230
|
+
tags.forEach((t) => {
|
|
231
|
+
tagMap[t.name] = t;
|
|
232
|
+
});
|
|
233
|
+
const collectionChildren = new Set(tags.map((t) => t.uid));
|
|
234
|
+
tags.forEach((t) => {
|
|
235
|
+
t["x-scalar-children"]?.forEach((c) => {
|
|
236
|
+
const nestedUid = tagMap[c.tagName]?.uid;
|
|
237
|
+
if (nestedUid) {
|
|
238
|
+
t.children.push(nestedUid);
|
|
239
|
+
collectionChildren.delete(nestedUid);
|
|
240
|
+
}
|
|
310
241
|
});
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
t
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const collection = collectionSchema.parse({
|
|
365
|
-
...slugObj,
|
|
366
|
-
...schema,
|
|
367
|
-
watchMode,
|
|
368
|
-
documentUrl,
|
|
369
|
-
useCollectionSecurity,
|
|
370
|
-
requests: requests.map((r) => r.uid),
|
|
371
|
-
servers: collectionServers.map((s) => s.uid),
|
|
372
|
-
tags: tags.map((t) => t.uid),
|
|
373
|
-
children: [...collectionChildren],
|
|
374
|
-
security: schema.security ?? [{}],
|
|
375
|
-
selectedServerUid: collectionServers?.[0]?.uid,
|
|
376
|
-
selectedSecuritySchemeUids,
|
|
377
|
-
components: {
|
|
378
|
-
...schema.components,
|
|
379
|
-
},
|
|
380
|
-
securitySchemes: securitySchemes.map((s) => s.uid),
|
|
381
|
-
});
|
|
382
|
-
const end = performance.now();
|
|
383
|
-
console.log(`workspace: ${Math.round(end - start)} ms`);
|
|
384
|
-
/**
|
|
385
|
-
* Servers and requests will be saved in top level maps and indexed via UID to
|
|
386
|
-
* maintain specification relationships
|
|
387
|
-
*/
|
|
388
|
-
return {
|
|
389
|
-
error: false,
|
|
390
|
-
servers: [...collectionServers, ...operationServers],
|
|
391
|
-
schema,
|
|
392
|
-
requests,
|
|
393
|
-
examples,
|
|
394
|
-
collection,
|
|
395
|
-
tags,
|
|
396
|
-
securitySchemes,
|
|
397
|
-
};
|
|
242
|
+
});
|
|
243
|
+
requests.forEach((r) => {
|
|
244
|
+
if (r.tags?.length) {
|
|
245
|
+
r.tags.forEach((t) => {
|
|
246
|
+
tagMap[t]?.children.push(r.uid);
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
collectionChildren.add(r.uid);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const examples = [];
|
|
253
|
+
requests.forEach((request) => {
|
|
254
|
+
const example = createExampleFromRequest(request, "Default Example");
|
|
255
|
+
examples.push(example);
|
|
256
|
+
request.examples.push(example.uid);
|
|
257
|
+
});
|
|
258
|
+
const securityRequirements = (schema.security ?? []).map((s) => {
|
|
259
|
+
const keys = Object.keys(s);
|
|
260
|
+
return keys.length > 1 ? keys : keys[0];
|
|
261
|
+
}).filter(isDefined);
|
|
262
|
+
const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat();
|
|
263
|
+
const selectedSecuritySchemeUids = (securityRequirements.length || preferredSecurityNames?.length) && useCollectionSecurity ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap) : [];
|
|
264
|
+
const slugObj = slug?.length ? { uid: getSlugUid(slug) } : {};
|
|
265
|
+
const collection = collectionSchema.parse({
|
|
266
|
+
...slugObj,
|
|
267
|
+
...schema,
|
|
268
|
+
watchMode,
|
|
269
|
+
documentUrl,
|
|
270
|
+
useCollectionSecurity,
|
|
271
|
+
requests: requests.map((r) => r.uid),
|
|
272
|
+
servers: collectionServers.map((s) => s.uid),
|
|
273
|
+
tags: tags.map((t) => t.uid),
|
|
274
|
+
children: [...collectionChildren],
|
|
275
|
+
security: schema.security ?? [{}],
|
|
276
|
+
selectedServerUid: collectionServers?.[0]?.uid,
|
|
277
|
+
selectedSecuritySchemeUids,
|
|
278
|
+
components: {
|
|
279
|
+
...schema.components
|
|
280
|
+
},
|
|
281
|
+
securitySchemes: securitySchemes.map((s) => s.uid)
|
|
282
|
+
});
|
|
283
|
+
const end = performance.now();
|
|
284
|
+
console.log(`workspace: ${Math.round(end - start)} ms`);
|
|
285
|
+
return {
|
|
286
|
+
error: false,
|
|
287
|
+
servers: [...collectionServers, ...operationServers],
|
|
288
|
+
schema,
|
|
289
|
+
requests,
|
|
290
|
+
examples,
|
|
291
|
+
collection,
|
|
292
|
+
tags,
|
|
293
|
+
securitySchemes
|
|
294
|
+
};
|
|
398
295
|
}
|
|
399
|
-
/**
|
|
400
|
-
* Retrieves a list of servers from an OpenAPI document and converts them to a list of Server entities.
|
|
401
|
-
*/
|
|
402
296
|
function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
// Use the base server URL (if provided)
|
|
414
|
-
if (baseServerURL) {
|
|
415
|
-
parsedSchema.url = combineUrlAndPath(baseServerURL, parsedSchema.url);
|
|
416
|
-
return parsedSchema;
|
|
417
|
-
}
|
|
418
|
-
// Fallback to the current window origin
|
|
419
|
-
const fallbackUrl = getFallbackUrl();
|
|
420
|
-
if (fallbackUrl) {
|
|
421
|
-
parsedSchema.url = combineUrlAndPath(fallbackUrl, parsedSchema.url.replace(/^\//, ''));
|
|
422
|
-
return parsedSchema;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
// Must be good, return it
|
|
426
|
-
return parsedSchema;
|
|
297
|
+
if (!servers || !Array.isArray(servers)) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
return servers.map((server) => {
|
|
301
|
+
try {
|
|
302
|
+
const parsedSchema = serverSchema.parse(server);
|
|
303
|
+
if (parsedSchema?.url?.startsWith("/")) {
|
|
304
|
+
if (baseServerURL) {
|
|
305
|
+
parsedSchema.url = combineUrlAndPath(baseServerURL, parsedSchema.url);
|
|
306
|
+
return parsedSchema;
|
|
427
307
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
// Return undefined to remove the server
|
|
433
|
-
return undefined;
|
|
308
|
+
const fallbackUrl = getFallbackUrl();
|
|
309
|
+
if (fallbackUrl) {
|
|
310
|
+
parsedSchema.url = combineUrlAndPath(fallbackUrl, parsedSchema.url.replace(/^\//, ""));
|
|
311
|
+
return parsedSchema;
|
|
434
312
|
}
|
|
435
|
-
|
|
436
|
-
|
|
313
|
+
}
|
|
314
|
+
return parsedSchema;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.warn("Oops, that\u2019s an invalid server configuration.");
|
|
317
|
+
console.warn("Server:", server);
|
|
318
|
+
console.warn("Error:", error);
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
}).filter(isDefined);
|
|
437
322
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Fallback to the current window.location.origin, if available
|
|
440
|
-
*/
|
|
441
323
|
function getFallbackUrl() {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
324
|
+
if (typeof window === "undefined") {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
if (typeof window?.location?.origin !== "string") {
|
|
328
|
+
return void 0;
|
|
329
|
+
}
|
|
330
|
+
return window.location.origin;
|
|
449
331
|
}
|
|
450
|
-
|
|
451
|
-
|
|
332
|
+
export {
|
|
333
|
+
getSelectedSecuritySchemeUids,
|
|
334
|
+
getServersFromOpenApiDocument,
|
|
335
|
+
getSlugUid,
|
|
336
|
+
importSpecToWorkspace,
|
|
337
|
+
parseSchema
|
|
338
|
+
};
|
|
339
|
+
//# sourceMappingURL=import-spec.js.map
|