@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.
Files changed (280) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/entities/cookie/cookie.js +14 -13
  3. package/dist/entities/cookie/cookie.js.map +7 -0
  4. package/dist/entities/cookie/index.d.ts +1 -1
  5. package/dist/entities/cookie/index.d.ts.map +1 -1
  6. package/dist/entities/cookie/index.js +5 -1
  7. package/dist/entities/cookie/index.js.map +7 -0
  8. package/dist/entities/environment/environment.js +10 -9
  9. package/dist/entities/environment/environment.js.map +7 -0
  10. package/dist/entities/environment/index.d.ts +1 -1
  11. package/dist/entities/environment/index.d.ts.map +1 -1
  12. package/dist/entities/environment/index.js +5 -1
  13. package/dist/entities/environment/index.js.map +7 -0
  14. package/dist/entities/hotkeys/hotkeys.js +109 -116
  15. package/dist/entities/hotkeys/hotkeys.js.map +7 -0
  16. package/dist/entities/hotkeys/index.d.ts +1 -1
  17. package/dist/entities/hotkeys/index.d.ts.map +1 -1
  18. package/dist/entities/hotkeys/index.js +6 -1
  19. package/dist/entities/hotkeys/index.js.map +7 -0
  20. package/dist/entities/shared/index.d.ts +1 -1
  21. package/dist/entities/shared/index.d.ts.map +1 -1
  22. package/dist/entities/shared/index.js +7 -1
  23. package/dist/entities/shared/index.js.map +7 -0
  24. package/dist/entities/shared/utility.js +9 -12
  25. package/dist/entities/shared/utility.js.map +7 -0
  26. package/dist/entities/spec/collection.d.ts.map +1 -1
  27. package/dist/entities/spec/collection.js +91 -94
  28. package/dist/entities/spec/collection.js.map +7 -0
  29. package/dist/entities/spec/index.d.ts +8 -8
  30. package/dist/entities/spec/index.d.ts.map +1 -1
  31. package/dist/entities/spec/index.js +59 -9
  32. package/dist/entities/spec/index.js.map +7 -0
  33. package/dist/entities/spec/operation.d.ts +1 -1
  34. package/dist/entities/spec/operation.d.ts.map +1 -1
  35. package/dist/entities/spec/operation.js +5 -8
  36. package/dist/entities/spec/operation.js.map +7 -0
  37. package/dist/entities/spec/operation.test.js +43 -0
  38. package/dist/entities/spec/operation.test.js.map +7 -0
  39. package/dist/entities/spec/parameters.d.ts +1 -1
  40. package/dist/entities/spec/parameters.d.ts.map +1 -1
  41. package/dist/entities/spec/parameters.js +40 -38
  42. package/dist/entities/spec/parameters.js.map +7 -0
  43. package/dist/entities/spec/parameters.test.js +71 -0
  44. package/dist/entities/spec/parameters.test.js.map +7 -0
  45. package/dist/entities/spec/request-example.test.js +637 -0
  46. package/dist/entities/spec/request-example.test.js.map +7 -0
  47. package/dist/entities/spec/request-examples.d.ts +3 -3
  48. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  49. package/dist/entities/spec/request-examples.js +323 -338
  50. package/dist/entities/spec/request-examples.js.map +7 -0
  51. package/dist/entities/spec/requests.d.ts +6 -8
  52. package/dist/entities/spec/requests.d.ts.map +1 -1
  53. package/dist/entities/spec/requests.js +80 -101
  54. package/dist/entities/spec/requests.js.map +7 -0
  55. package/dist/entities/spec/server.js +47 -63
  56. package/dist/entities/spec/server.js.map +7 -0
  57. package/dist/entities/spec/server.test.js +120 -0
  58. package/dist/entities/spec/server.test.js.map +7 -0
  59. package/dist/entities/spec/spec-objects.d.ts.map +1 -1
  60. package/dist/entities/spec/spec-objects.js +77 -121
  61. package/dist/entities/spec/spec-objects.js.map +7 -0
  62. package/dist/entities/spec/spec-objects.test.js +205 -0
  63. package/dist/entities/spec/spec-objects.test.js.map +7 -0
  64. package/dist/entities/spec/x-scalar-environments.js +21 -18
  65. package/dist/entities/spec/x-scalar-environments.js.map +7 -0
  66. package/dist/entities/spec/x-scalar-environments.test.js +11 -0
  67. package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
  68. package/dist/entities/spec/x-scalar-secrets.js +8 -6
  69. package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
  70. package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
  71. package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
  72. package/dist/entities/workspace/index.d.ts +1 -1
  73. package/dist/entities/workspace/index.d.ts.map +1 -1
  74. package/dist/entities/workspace/index.js +7 -1
  75. package/dist/entities/workspace/index.js.map +7 -0
  76. package/dist/entities/workspace/workspace.js +46 -50
  77. package/dist/entities/workspace/workspace.js.map +7 -0
  78. package/dist/helpers/create-hash.js +15 -18
  79. package/dist/helpers/create-hash.js.map +7 -0
  80. package/dist/helpers/ensure-protocol.js +9 -10
  81. package/dist/helpers/ensure-protocol.js.map +7 -0
  82. package/dist/helpers/ensure-protocol.test.js +70 -0
  83. package/dist/helpers/ensure-protocol.test.js.map +7 -0
  84. package/dist/helpers/fetch-document.js +24 -32
  85. package/dist/helpers/fetch-document.js.map +7 -0
  86. package/dist/helpers/fetch-document.test.js +63 -0
  87. package/dist/helpers/fetch-document.test.js.map +7 -0
  88. package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
  89. package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
  90. package/dist/helpers/find-variables.d.ts +1 -1
  91. package/dist/helpers/find-variables.d.ts.map +1 -1
  92. package/dist/helpers/find-variables.js +6 -8
  93. package/dist/helpers/find-variables.js.map +7 -0
  94. package/dist/helpers/find-variables.test.js +20 -0
  95. package/dist/helpers/find-variables.test.js.map +7 -0
  96. package/dist/helpers/http-methods.d.ts +1 -1
  97. package/dist/helpers/http-methods.d.ts.map +1 -1
  98. package/dist/helpers/http-methods.js +60 -66
  99. package/dist/helpers/http-methods.js.map +7 -0
  100. package/dist/helpers/http-status-codes.js +319 -317
  101. package/dist/helpers/http-status-codes.js.map +7 -0
  102. package/dist/helpers/index.d.ts +27 -27
  103. package/dist/helpers/index.d.ts.map +1 -1
  104. package/dist/helpers/index.js +73 -27
  105. package/dist/helpers/index.js.map +7 -0
  106. package/dist/helpers/is-defined.js +5 -14
  107. package/dist/helpers/is-defined.js.map +7 -0
  108. package/dist/helpers/is-defined.test.js +37 -0
  109. package/dist/helpers/is-defined.test.js.map +7 -0
  110. package/dist/helpers/is-local-url.js +11 -16
  111. package/dist/helpers/is-local-url.js.map +7 -0
  112. package/dist/helpers/is-local-url.test.js +40 -0
  113. package/dist/helpers/is-local-url.test.js.map +7 -0
  114. package/dist/helpers/is-valid-url.js +9 -18
  115. package/dist/helpers/is-valid-url.js.map +7 -0
  116. package/dist/helpers/is-valid-url.test.js +17 -0
  117. package/dist/helpers/is-valid-url.test.js.map +7 -0
  118. package/dist/helpers/iterate-title.js +11 -15
  119. package/dist/helpers/iterate-title.js.map +7 -0
  120. package/dist/helpers/json2xml.js +40 -47
  121. package/dist/helpers/json2xml.js.map +7 -0
  122. package/dist/helpers/json2xml.test.js +19 -0
  123. package/dist/helpers/json2xml.test.js.map +7 -0
  124. package/dist/helpers/local-storage.js +13 -15
  125. package/dist/helpers/local-storage.js.map +7 -0
  126. package/dist/helpers/make-url-absolute.js +11 -17
  127. package/dist/helpers/make-url-absolute.js.map +7 -0
  128. package/dist/helpers/make-url-absolute.test.js +61 -0
  129. package/dist/helpers/make-url-absolute.test.js.map +7 -0
  130. package/dist/helpers/merge-urls.js +50 -75
  131. package/dist/helpers/merge-urls.js.map +7 -0
  132. package/dist/helpers/merge-urls.test.js +339 -0
  133. package/dist/helpers/merge-urls.test.js.map +7 -0
  134. package/dist/helpers/normalize-mime-type-object.js +21 -31
  135. package/dist/helpers/normalize-mime-type-object.js.map +7 -0
  136. package/dist/helpers/normalize-mime-type-object.test.js +53 -0
  137. package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
  138. package/dist/helpers/normalize-mime-type.js +8 -18
  139. package/dist/helpers/normalize-mime-type.js.map +7 -0
  140. package/dist/helpers/normalize-mime-type.test.js +33 -0
  141. package/dist/helpers/normalize-mime-type.test.js.map +7 -0
  142. package/dist/helpers/object.js +12 -18
  143. package/dist/helpers/object.js.map +7 -0
  144. package/dist/helpers/omit-undefined-values.js +17 -19
  145. package/dist/helpers/omit-undefined-values.js.map +7 -0
  146. package/dist/helpers/omit-undefined-values.test.js +89 -0
  147. package/dist/helpers/omit-undefined-values.test.js.map +7 -0
  148. package/dist/helpers/parse.js +71 -83
  149. package/dist/helpers/parse.js.map +7 -0
  150. package/dist/helpers/parse.test.js +45 -0
  151. package/dist/helpers/parse.test.js.map +7 -0
  152. package/dist/helpers/pretty-print-json.js +31 -35
  153. package/dist/helpers/pretty-print-json.js.map +7 -0
  154. package/dist/helpers/pretty-print-json.test.js +28 -0
  155. package/dist/helpers/pretty-print-json.test.js.map +7 -0
  156. package/dist/helpers/redirect-to-proxy.js +46 -83
  157. package/dist/helpers/redirect-to-proxy.js.map +7 -0
  158. package/dist/helpers/redirect-to-proxy.test.js +54 -0
  159. package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
  160. package/dist/helpers/regex-helpers.js +11 -9
  161. package/dist/helpers/regex-helpers.js.map +7 -0
  162. package/dist/helpers/regex-helpers.test.js +154 -0
  163. package/dist/helpers/regex-helpers.test.js.map +7 -0
  164. package/dist/helpers/replace-variables.js +13 -16
  165. package/dist/helpers/replace-variables.js.map +7 -0
  166. package/dist/helpers/replace-variables.test.js +30 -0
  167. package/dist/helpers/replace-variables.test.js.map +7 -0
  168. package/dist/helpers/schema-model.js +15 -14
  169. package/dist/helpers/schema-model.js.map +7 -0
  170. package/dist/helpers/security/get-schemes.d.ts +1 -1
  171. package/dist/helpers/security/get-schemes.d.ts.map +1 -1
  172. package/dist/helpers/security/get-schemes.js +7 -9
  173. package/dist/helpers/security/get-schemes.js.map +7 -0
  174. package/dist/helpers/security/get-schemes.test.js +71 -0
  175. package/dist/helpers/security/get-schemes.test.js.map +7 -0
  176. package/dist/helpers/security/has-token.js +18 -19
  177. package/dist/helpers/security/has-token.js.map +7 -0
  178. package/dist/helpers/security/has-token.test.js +157 -0
  179. package/dist/helpers/security/has-token.test.js.map +7 -0
  180. package/dist/helpers/security/index.d.ts +2 -2
  181. package/dist/helpers/security/index.d.ts.map +1 -1
  182. package/dist/helpers/security/index.js +7 -2
  183. package/dist/helpers/security/index.js.map +7 -0
  184. package/dist/helpers/should-ignore-entity.d.ts +2 -2
  185. package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
  186. package/dist/helpers/should-ignore-entity.js +5 -6
  187. package/dist/helpers/should-ignore-entity.js.map +7 -0
  188. package/dist/helpers/ssr-state.js +6 -6
  189. package/dist/helpers/ssr-state.js.map +7 -0
  190. package/dist/helpers/string.js +6 -18
  191. package/dist/helpers/string.js.map +7 -0
  192. package/dist/migrations/data-version.js +7 -17
  193. package/dist/migrations/data-version.js.map +7 -0
  194. package/dist/migrations/generate-types.js +56 -0
  195. package/dist/migrations/generate-types.js.map +7 -0
  196. package/dist/migrations/index.d.ts +3 -3
  197. package/dist/migrations/index.d.ts.map +1 -1
  198. package/dist/migrations/index.js +10 -3
  199. package/dist/migrations/index.js.map +7 -0
  200. package/dist/migrations/local-storage.d.ts +1 -1
  201. package/dist/migrations/local-storage.d.ts.map +1 -1
  202. package/dist/migrations/local-storage.js +27 -32
  203. package/dist/migrations/local-storage.js.map +7 -0
  204. package/dist/migrations/migrator.d.ts +1 -1
  205. package/dist/migrations/migrator.d.ts.map +1 -1
  206. package/dist/migrations/migrator.js +51 -58
  207. package/dist/migrations/migrator.js.map +7 -0
  208. package/dist/migrations/semver.js +23 -25
  209. package/dist/migrations/semver.js.map +7 -0
  210. package/dist/migrations/semver.test.js +21 -0
  211. package/dist/migrations/semver.test.js.map +7 -0
  212. package/dist/migrations/v-0.0.0/types.generated.js +1 -0
  213. package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
  214. package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
  215. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
  216. package/dist/migrations/v-2.1.0/migration.js +256 -273
  217. package/dist/migrations/v-2.1.0/migration.js.map +7 -0
  218. package/dist/migrations/v-2.1.0/types.generated.js +1 -0
  219. package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
  220. package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
  221. package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
  222. package/dist/migrations/v-2.2.0/migration.js +95 -100
  223. package/dist/migrations/v-2.2.0/migration.js.map +7 -0
  224. package/dist/migrations/v-2.2.0/types.generated.js +1 -0
  225. package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
  226. package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
  227. package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
  228. package/dist/migrations/v-2.3.0/migration.js +47 -46
  229. package/dist/migrations/v-2.3.0/migration.js.map +7 -0
  230. package/dist/migrations/v-2.3.0/types.generated.js +1 -0
  231. package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
  232. package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
  233. package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
  234. package/dist/migrations/v-2.4.0/migration.js +24 -26
  235. package/dist/migrations/v-2.4.0/migration.js.map +7 -0
  236. package/dist/migrations/v-2.4.0/migration.test.js +90 -0
  237. package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
  238. package/dist/migrations/v-2.4.0/types.generated.js +1 -0
  239. package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
  240. package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
  241. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  242. package/dist/migrations/v-2.5.0/migration.js +135 -119
  243. package/dist/migrations/v-2.5.0/migration.js.map +7 -0
  244. package/dist/migrations/v-2.5.0/migration.test.js +108 -0
  245. package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
  246. package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
  247. package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
  248. package/dist/migrations/v-2.5.0/types.generated.js +1 -0
  249. package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
  250. package/dist/spec-getters/get-example-from-schema.js +206 -268
  251. package/dist/spec-getters/get-example-from-schema.js.map +7 -0
  252. package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
  253. package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
  254. package/dist/spec-getters/get-parameters-from-operation.js +22 -42
  255. package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
  256. package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
  257. package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
  258. package/dist/spec-getters/get-request-body-from-operation.js +110 -162
  259. package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
  260. package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
  261. package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
  262. package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
  263. package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
  264. package/dist/spec-getters/get-server-variable-examples.js +12 -11
  265. package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
  266. package/dist/spec-getters/index.d.ts +4 -4
  267. package/dist/spec-getters/index.d.ts.map +1 -1
  268. package/dist/spec-getters/index.js +11 -4
  269. package/dist/spec-getters/index.js.map +7 -0
  270. package/dist/transforms/import-spec.d.ts +6 -6
  271. package/dist/transforms/import-spec.d.ts.map +1 -1
  272. package/dist/transforms/import-spec.js +313 -425
  273. package/dist/transforms/import-spec.js.map +7 -0
  274. package/dist/transforms/import-spec.test.js +1124 -0
  275. package/dist/transforms/import-spec.test.js.map +7 -0
  276. package/dist/transforms/index.d.ts +1 -1
  277. package/dist/transforms/index.d.ts.map +1 -1
  278. package/dist/transforms/index.js +13 -1
  279. package/dist/transforms/index.js.map +7 -0
  280. package/package.json +10 -11
@@ -1,451 +1,339 @@
1
- import { keysOf } from '@scalar/object-utils/arrays';
2
- import { load, upgrade, dereference } 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 { securitySchemeSchema } from '@scalar/types/entities';
13
-
14
- /** Takes a string or object and parses it into an openapi spec compliant schema */
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
- if (spec === null || (typeof spec === 'string' && spec.trim() === '')) {
17
- console.warn('[@scalar/oas-utils] Empty OpenAPI document provided.');
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
- * Temporary fix for the parser returning an empty array
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
- // Set the first security requirement if no preferred security schemes are set
57
- const names = securityRequirements[0] && !preferredSecurityNames.length ? [securityRequirements[0]] : preferredSecurityNames;
58
- // Map names to uids
59
- const uids = names
60
- .map((name) => Array.isArray(name) ? name.map((k) => securitySchemeMap[k]).filter(isDefined) : securitySchemeMap[name])
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
- * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
68
- *
69
- * The imported entities maintain a close mapping to the original OpenAPI specification to enable:
70
- * - Bi-directional translation between spec and workspace entities
71
- * - Preservation of specification details and structure
72
- * - Accurate representation of relationships between components
73
- *
74
- * Relationships between entities are maintained through unique identifiers (UIDs) which allow:
75
- * - Flexible organization at different levels (workspace, collection, request)
76
- * - Proper linking between related components
77
- * - Easy lookup and reference of dependent entities
78
- */
79
- async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: configuredServers, useCollectionSecurity = false, slug, shouldLoad, watchMode = false, } = {}) {
80
- const { schema, errors } = await parseSchema(spec, { shouldLoad });
81
- const importWarnings = [...errors.map((e) => e.message)];
82
- if (!schema) {
83
- return { importWarnings, error: true, collection: undefined };
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
- // Some entities will be broken out as individual lists for modification in the workspace
87
- const start = performance.now();
88
- const requests = [];
89
- // Add the base server url to collection servers
90
- const collectionServers = getServersFromOpenApiDocument(configuredServers || schema.servers, {
91
- baseServerURL,
92
- });
93
- // Store operation servers
94
- const operationServers = [];
95
- // Fallback to the current window.location.origin if no servers are provided
96
- if (!collectionServers.length) {
97
- const fallbackUrl = getFallbackUrl();
98
- if (fallbackUrl) {
99
- collectionServers.push(serverSchema.parse({ url: fallbackUrl }));
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
- * List of all tag strings. For non compliant specs we may need to
104
- * add top level tag objects for missing tag objects
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
- // For oauth2 we need to add the type to the flows + prefill from authentication
124
- if (payload.type === 'oauth2' && payload.flows) {
125
- const flowKeys = Object.keys(payload.flows);
126
- flowKeys.forEach((key) => {
127
- if (!payload.flows?.[key] || _scheme.type !== 'oauth2') {
128
- return;
129
- }
130
- const authFlow = authentication?.securitySchemes?.[nameKey]?.flows?.[key] ?? {};
131
- // This part handles setting of flows via the new auth config, the rest can be removed in a future version
132
- payload.flows[key] = {
133
- ...(_scheme.flows?.[key] ?? {}),
134
- ...authFlow,
135
- };
136
- const flow = payload.flows[key];
137
- // Set the type
138
- flow.type = key;
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
- // Otherwise we just prefill - old deprecated config
175
- else if (authentication) {
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
- const scheme = schemaModel(payload, securitySchemeSchema, false);
200
- if (!scheme) {
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
- return scheme;
204
- })
205
- .filter((v) => !!v);
206
- // Map of security scheme names to UIDs
207
- const securitySchemeMap = {};
208
- securitySchemes.forEach((s) => {
209
- securitySchemeMap[s.nameKey] = s.uid;
210
- });
211
- // ---------------------------------------------------------------------------
212
- // REQUEST HANDLING
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
- // Path level servers must be saved
219
- const pathServers = serverSchema.array().parse(path.servers ?? []);
220
- for (const server of pathServers) {
221
- collectionServers.push(server);
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
- // Creates a sorted array of methods based on the path object.
224
- const methods = Object.keys(path).filter(isHttpMethod);
225
- methods.forEach((method) => {
226
- const operation = path[method];
227
- const operationLevelServers = serverSchema.array().parse(operation.servers ?? []);
228
- for (const server of operationLevelServers) {
229
- operationServers.push(server);
230
- }
231
- // We will save a list of all tags to ensure they exists at the top level
232
- // TODO: make sure we add any loose requests with no tags to the collection children
233
- operation.tags?.forEach((t) => tagNames.add(t));
234
- // Remove security here and add it correctly below
235
- const { security: operationSecurity, ...operationWithoutSecurity } = operation;
236
- const securityRequirements = (operationSecurity ?? schema.security ?? [])
237
- .map((s) => {
238
- const keys = Object.keys(s);
239
- return keys.length > 1 ? keys : keys[0];
240
- })
241
- .filter(isDefined);
242
- // Filter the preferred security schemes to only include the ones that are in the security requirements
243
- const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat().filter((name) => {
244
- // Match up complex security requirements, array to array
245
- if (Array.isArray(name)) {
246
- // We match every element in the array
247
- return securityRequirements.some((r) => Array.isArray(r) && r.length === name.length && r.every((v, i) => v === name[i]));
248
- }
249
- return securityRequirements.includes(name);
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
- // TAG HANDLING
300
- // TODO: We may need to handle de-duping tags
301
- const tags = schemaModel(schema?.tags ?? [], tagSchema.array(), false) ?? [];
302
- // Delete any tag names that already have a definition
303
- tags.forEach((t) => tagNames.delete(t.name));
304
- // Add an entry for any tags that are used but do not have a definition
305
- tagNames.forEach((name) => name && tags.push(tagSchema.parse({ name })));
306
- // Tag name to UID map
307
- const tagMap = {};
308
- tags.forEach((t) => {
309
- tagMap[t.name] = t;
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
- // Add all tags by default. We will remove nested ones
312
- const collectionChildren = new Set(tags.map((t) => t.uid));
313
- // Nested folders go before any requests
314
- tags.forEach((t) => {
315
- t['x-scalar-children']?.forEach((c) => {
316
- // Add the uid to the appropriate parent.children
317
- const nestedUid = tagMap[c.tagName]?.uid;
318
- if (nestedUid) {
319
- t.children.push(nestedUid);
320
- // Remove the nested uid from the root folder
321
- collectionChildren.delete(nestedUid);
322
- }
323
- });
324
- });
325
- // Add the request UIDs to the tag children (or collection root)
326
- requests.forEach((r) => {
327
- if (r.tags?.length) {
328
- r.tags.forEach((t) => {
329
- tagMap[t]?.children.push(r.uid);
330
- });
331
- }
332
- else {
333
- collectionChildren.add(r.uid);
334
- }
335
- });
336
- // ---------------------------------------------------------------------------
337
- const examples = [];
338
- // Ensure each request has at least 1 example
339
- requests.forEach((request) => {
340
- // TODO: Need to handle parsing examples
341
- // if (request['x-scalar-examples']) return
342
- // Create the initial example
343
- const example = createExampleFromRequest(request, 'Default Example');
344
- examples.push(example);
345
- request.examples.push(example.uid);
346
- });
347
- // ---------------------------------------------------------------------------
348
- // Generate Collection
349
- // Grab the security requirements for this operation
350
- const securityRequirements = (schema.security ?? [])
351
- .map((s) => {
352
- const keys = Object.keys(s);
353
- return keys.length > 1 ? keys : keys[0];
354
- })
355
- .filter(isDefined);
356
- // Here we do not filter these as we let the preferredSecurityScheme override the requirements
357
- const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat();
358
- // Set the initially selected security scheme
359
- const selectedSecuritySchemeUids = (securityRequirements.length || preferredSecurityNames?.length) && useCollectionSecurity
360
- ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
361
- : [];
362
- // Set the uid as a prefixed slug if we have one
363
- const slugObj = slug?.length ? { uid: getSlugUid(slug) } : {};
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
- if (!servers || !Array.isArray(servers)) {
404
- return [];
405
- }
406
- return servers
407
- .map((server) => {
408
- try {
409
- // Validate the server against the schema
410
- const parsedSchema = serverSchema.parse(server);
411
- // Prepend with the base server URL (if the given URL is relative)
412
- if (parsedSchema?.url?.startsWith('/')) {
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
- catch (error) {
429
- console.warn('Oops, that’s an invalid server configuration.');
430
- console.warn('Server:', server);
431
- console.warn('Error:', error);
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
- .filter(isDefined);
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
- if (typeof window === 'undefined') {
443
- return undefined;
444
- }
445
- if (typeof window?.location?.origin !== 'string') {
446
- return undefined;
447
- }
448
- return window.location.origin;
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
- export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, getSlugUid, importSpecToWorkspace, parseSchema };
332
+ export {
333
+ getSelectedSecuritySchemeUids,
334
+ getServersFromOpenApiDocument,
335
+ getSlugUid,
336
+ importSpecToWorkspace,
337
+ parseSchema
338
+ };
339
+ //# sourceMappingURL=import-spec.js.map