@scalar/oas-utils 0.2.43 → 0.2.44

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 (188) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/diff/diff.d.ts +13 -0
  3. package/dist/diff/diff.d.ts.map +1 -0
  4. package/dist/diff/index.d.ts +1 -0
  5. package/dist/diff/index.d.ts.map +1 -0
  6. package/dist/diff/index.js +1 -0
  7. package/dist/entities/{workspace/cookie → cookie}/cookie.d.ts +1 -17
  8. package/dist/entities/cookie/cookie.d.ts.map +1 -0
  9. package/dist/entities/{workspace/cookie → cookie}/cookie.js +1 -4
  10. package/dist/entities/cookie/index.d.ts.map +1 -0
  11. package/dist/entities/cookie/index.js +1 -0
  12. package/dist/entities/environment/environment.d.ts +24 -0
  13. package/dist/entities/environment/environment.d.ts.map +1 -0
  14. package/dist/entities/environment/environment.js +12 -0
  15. package/dist/entities/environment/index.d.ts.map +1 -0
  16. package/dist/entities/environment/index.js +1 -0
  17. package/dist/entities/{workspace/consts/hot-keys.d.ts → hotkeys/hotkeys.d.ts} +2 -2
  18. package/dist/entities/hotkeys/hotkeys.d.ts.map +1 -0
  19. package/dist/entities/{workspace/consts/hot-keys.js → hotkeys/hotkeys.js} +1 -0
  20. package/dist/entities/hotkeys/index.d.ts +2 -0
  21. package/dist/entities/hotkeys/index.d.ts.map +1 -0
  22. package/dist/entities/hotkeys/index.js +1 -0
  23. package/dist/entities/index.d.ts +1 -1
  24. package/dist/entities/index.d.ts.map +1 -1
  25. package/dist/entities/index.js +1 -1
  26. package/dist/entities/shared/index.d.ts.map +1 -0
  27. package/dist/entities/shared/utility.d.ts.map +1 -0
  28. package/dist/entities/spec/collection.d.ts +489 -0
  29. package/dist/entities/spec/collection.d.ts.map +1 -0
  30. package/dist/entities/spec/collection.js +63 -0
  31. package/dist/entities/spec/index.d.ts +10 -0
  32. package/dist/entities/spec/index.d.ts.map +1 -0
  33. package/dist/entities/spec/index.js +7 -0
  34. package/dist/entities/spec/parameters.d.ts +42 -0
  35. package/dist/entities/spec/parameters.d.ts.map +1 -0
  36. package/dist/entities/spec/parameters.js +30 -0
  37. package/dist/entities/spec/request-examples.d.ts +915 -0
  38. package/dist/entities/spec/request-examples.d.ts.map +1 -0
  39. package/dist/entities/spec/request-examples.js +168 -0
  40. package/dist/entities/spec/requests.d.ts +317 -0
  41. package/dist/entities/spec/requests.d.ts.map +1 -0
  42. package/dist/entities/{workspace/spec → spec}/requests.js +56 -32
  43. package/dist/entities/spec/security.d.ts +964 -0
  44. package/dist/entities/spec/security.d.ts.map +1 -0
  45. package/dist/entities/spec/security.js +222 -0
  46. package/dist/entities/spec/server.d.ts +82 -0
  47. package/dist/entities/spec/server.d.ts.map +1 -0
  48. package/dist/entities/{workspace/server → spec}/server.js +11 -13
  49. package/dist/entities/spec/spec-objects.d.ts +279 -0
  50. package/dist/entities/spec/spec-objects.d.ts.map +1 -0
  51. package/dist/entities/{workspace/collection/collection.js → spec/spec-objects.js} +21 -45
  52. package/dist/entities/workspace/index.js +1 -1
  53. package/dist/entities/workspace/workspace.d.ts +24 -43
  54. package/dist/entities/workspace/workspace.d.ts.map +1 -1
  55. package/dist/entities/workspace/workspace.js +6 -7
  56. package/dist/helpers/httpMethods.d.ts +16 -82
  57. package/dist/helpers/httpMethods.d.ts.map +1 -1
  58. package/dist/helpers/httpMethods.js +45 -41
  59. package/dist/helpers/index.d.ts +2 -0
  60. package/dist/helpers/index.d.ts.map +1 -1
  61. package/dist/helpers/index.js +4 -2
  62. package/dist/helpers/local-storage.d.ts +16 -0
  63. package/dist/helpers/local-storage.d.ts.map +1 -0
  64. package/dist/helpers/local-storage.js +17 -0
  65. package/dist/helpers/redirectToProxy.d.ts +2 -0
  66. package/dist/helpers/redirectToProxy.d.ts.map +1 -1
  67. package/dist/helpers/redirectToProxy.js +6 -7
  68. package/dist/helpers/regexHelpers.d.ts +2 -0
  69. package/dist/helpers/regexHelpers.d.ts.map +1 -0
  70. package/dist/helpers/regexHelpers.js +3 -0
  71. package/dist/helpers/schema-model.d.ts +2 -2
  72. package/dist/helpers/schema-model.d.ts.map +1 -1
  73. package/dist/helpers/schema-model.js +11 -17
  74. package/dist/migrations/data-version.d.ts +12 -0
  75. package/dist/migrations/data-version.d.ts.map +1 -0
  76. package/dist/migrations/data-version.js +13 -0
  77. package/dist/migrations/generate-types.d.ts +2 -0
  78. package/dist/migrations/generate-types.d.ts.map +1 -0
  79. package/dist/migrations/index.d.ts +4 -0
  80. package/dist/migrations/index.d.ts.map +1 -0
  81. package/dist/migrations/index.js +3 -0
  82. package/dist/migrations/local-storage.d.ts +8 -0
  83. package/dist/migrations/local-storage.d.ts.map +1 -0
  84. package/dist/migrations/local-storage.js +36 -0
  85. package/dist/migrations/migrator.d.ts +4 -0
  86. package/dist/migrations/migrator.d.ts.map +1 -0
  87. package/dist/migrations/migrator.js +40 -0
  88. package/dist/migrations/semver.d.ts +5 -0
  89. package/dist/migrations/semver.d.ts.map +1 -0
  90. package/dist/migrations/semver.js +25 -0
  91. package/dist/migrations/v-0.0.0/index.d.ts +2 -0
  92. package/dist/migrations/v-0.0.0/index.d.ts.map +1 -0
  93. package/dist/migrations/v-0.0.0/index.js +1 -0
  94. package/dist/migrations/v-0.0.0/types.generated.d.ts +347 -0
  95. package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -0
  96. package/dist/migrations/v-2.1.0/index.d.ts +3 -0
  97. package/dist/migrations/v-2.1.0/index.d.ts.map +1 -0
  98. package/dist/migrations/v-2.1.0/index.js +1 -0
  99. package/dist/migrations/v-2.1.0/migration.d.ts +334 -0
  100. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -0
  101. package/dist/migrations/v-2.1.0/migration.js +249 -0
  102. package/dist/migrations/v-2.1.0/types.generated.d.ts +42 -0
  103. package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -0
  104. package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
  105. package/dist/spec-getters/getExampleFromSchema.js +21 -8
  106. package/dist/spec-getters/getParametersFromOperation.d.ts +1 -1
  107. package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
  108. package/dist/spec-getters/getParametersFromOperation.js +8 -7
  109. package/dist/spec-getters/getRequestBodyFromOperation.d.ts +12 -40
  110. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  111. package/dist/spec-getters/getRequestBodyFromOperation.js +34 -23
  112. package/dist/spec-getters/getRequestFromOperation.d.ts.map +1 -1
  113. package/dist/spec-getters/getRequestFromOperation.js +1 -2
  114. package/dist/spec-getters/getServerVariableExamples.d.ts +4 -0
  115. package/dist/spec-getters/getServerVariableExamples.d.ts.map +1 -0
  116. package/dist/spec-getters/getServerVariableExamples.js +12 -0
  117. package/dist/spec-getters/index.d.ts +1 -0
  118. package/dist/spec-getters/index.d.ts.map +1 -1
  119. package/dist/spec-getters/index.js +1 -0
  120. package/dist/transforms/export-spec.d.ts +68 -0
  121. package/dist/transforms/export-spec.d.ts.map +1 -0
  122. package/dist/transforms/import-spec.d.ts +20 -68
  123. package/dist/transforms/import-spec.d.ts.map +1 -1
  124. package/dist/transforms/import-spec.js +209 -126
  125. package/package.json +42 -36
  126. package/dist/entities/workspace/collection/collection.d.ts +0 -330
  127. package/dist/entities/workspace/collection/collection.d.ts.map +0 -1
  128. package/dist/entities/workspace/collection/index.d.ts +0 -2
  129. package/dist/entities/workspace/collection/index.d.ts.map +0 -1
  130. package/dist/entities/workspace/collection/index.js +0 -1
  131. package/dist/entities/workspace/consts/hot-keys.d.ts.map +0 -1
  132. package/dist/entities/workspace/consts/index.d.ts +0 -2
  133. package/dist/entities/workspace/consts/index.d.ts.map +0 -1
  134. package/dist/entities/workspace/consts/index.js +0 -1
  135. package/dist/entities/workspace/cookie/cookie.d.ts.map +0 -1
  136. package/dist/entities/workspace/cookie/index.d.ts.map +0 -1
  137. package/dist/entities/workspace/cookie/index.js +0 -1
  138. package/dist/entities/workspace/environment/environment.d.ts +0 -55
  139. package/dist/entities/workspace/environment/environment.d.ts.map +0 -1
  140. package/dist/entities/workspace/environment/environment.js +0 -23
  141. package/dist/entities/workspace/environment/index.d.ts.map +0 -1
  142. package/dist/entities/workspace/environment/index.js +0 -1
  143. package/dist/entities/workspace/folder/folder.d.ts +0 -36
  144. package/dist/entities/workspace/folder/folder.d.ts.map +0 -1
  145. package/dist/entities/workspace/folder/folder.js +0 -21
  146. package/dist/entities/workspace/folder/index.d.ts +0 -2
  147. package/dist/entities/workspace/folder/index.d.ts.map +0 -1
  148. package/dist/entities/workspace/folder/index.js +0 -1
  149. package/dist/entities/workspace/security/index.d.ts +0 -3
  150. package/dist/entities/workspace/security/index.d.ts.map +0 -1
  151. package/dist/entities/workspace/security/index.js +0 -2
  152. package/dist/entities/workspace/security/security-requirement.d.ts +0 -13
  153. package/dist/entities/workspace/security/security-requirement.d.ts.map +0 -1
  154. package/dist/entities/workspace/security/security-requirement.js +0 -15
  155. package/dist/entities/workspace/security/security-schemes.d.ts +0 -696
  156. package/dist/entities/workspace/security/security-schemes.d.ts.map +0 -1
  157. package/dist/entities/workspace/security/security-schemes.js +0 -139
  158. package/dist/entities/workspace/server/index.d.ts +0 -2
  159. package/dist/entities/workspace/server/index.d.ts.map +0 -1
  160. package/dist/entities/workspace/server/index.js +0 -1
  161. package/dist/entities/workspace/server/server.d.ts +0 -91
  162. package/dist/entities/workspace/server/server.d.ts.map +0 -1
  163. package/dist/entities/workspace/shared/index.d.ts.map +0 -1
  164. package/dist/entities/workspace/shared/utility.d.ts.map +0 -1
  165. package/dist/entities/workspace/spec/components.d.ts +0 -3
  166. package/dist/entities/workspace/spec/components.d.ts.map +0 -1
  167. package/dist/entities/workspace/spec/index.d.ts +0 -5
  168. package/dist/entities/workspace/spec/index.d.ts.map +0 -1
  169. package/dist/entities/workspace/spec/index.js +0 -2
  170. package/dist/entities/workspace/spec/parameters.d.ts +0 -16
  171. package/dist/entities/workspace/spec/parameters.d.ts.map +0 -1
  172. package/dist/entities/workspace/spec/refs.d.ts +0 -30
  173. package/dist/entities/workspace/spec/refs.d.ts.map +0 -1
  174. package/dist/entities/workspace/spec/refs.js +0 -9
  175. package/dist/entities/workspace/spec/request-examples.d.ts +0 -1573
  176. package/dist/entities/workspace/spec/request-examples.d.ts.map +0 -1
  177. package/dist/entities/workspace/spec/request-examples.js +0 -96
  178. package/dist/entities/workspace/spec/requests.d.ts +0 -181
  179. package/dist/entities/workspace/spec/requests.d.ts.map +0 -1
  180. package/dist/entities/workspace/spec/spec.d.ts +0 -18
  181. package/dist/entities/workspace/spec/spec.d.ts.map +0 -1
  182. package/dist/entities/workspace/spec/spec.js +0 -8
  183. /package/dist/entities/{workspace/cookie → cookie}/index.d.ts +0 -0
  184. /package/dist/entities/{workspace/environment → environment}/index.d.ts +0 -0
  185. /package/dist/entities/{workspace/shared → shared}/index.d.ts +0 -0
  186. /package/dist/entities/{workspace/shared → shared}/index.js +0 -0
  187. /package/dist/entities/{workspace/shared → shared}/utility.d.ts +0 -0
  188. /package/dist/entities/{workspace/shared → shared}/utility.js +0 -0
@@ -1,3 +1,5 @@
1
+ /** Hard limit for rendering circular references */
2
+ const MAX_LEVELS_DEEP = 5;
1
3
  /**
2
4
  * We can use the `format` to generate some random values.
3
5
  */
@@ -38,9 +40,15 @@ function guessFromFormat(schema, fallback = '') {
38
40
  * This function takes a properties object and generates an example response content.
39
41
  */
40
42
  const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) => {
41
- // Break an infinite loop
42
- if (level > 5) {
43
- return null;
43
+ // Check whether it’s a circular reference
44
+ if (level === MAX_LEVELS_DEEP + 1) {
45
+ try {
46
+ // Fails if it contains a circular reference
47
+ JSON.stringify(schema);
48
+ }
49
+ catch {
50
+ return '[Circular Reference]';
51
+ }
44
52
  }
45
53
  // Sometimes, we just want the structure and no values.
46
54
  // But if `emptyString` is set, we do want to see some values.
@@ -82,7 +90,11 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
82
90
  return schema.enum[0];
83
91
  }
84
92
  // Check if the property is required
85
- const isObjectOrArray = schema.type === 'object' || schema.type === 'array';
93
+ const isObjectOrArray = schema.type === 'object' ||
94
+ schema.type === 'array' ||
95
+ !!schema.allOf?.at?.(0) ||
96
+ !!schema.anyOf?.at?.(0) ||
97
+ !!schema.oneOf?.at?.(0);
86
98
  if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {
87
99
  const isRequired = schema.required === true ||
88
100
  parentSchema?.required === true ||
@@ -183,10 +195,11 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
183
195
  if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
184
196
  return exampleValues[schema.type];
185
197
  }
186
- // Check if property has the `oneOf` key
187
- if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
188
- // Get the first item from the `oneOf` array
189
- const firstOneOfItem = schema.oneOf[0];
198
+ const discriminateSchema = schema.oneOf || schema.anyOf;
199
+ // Check if property has the `oneOf` | `anyOf` key
200
+ if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
201
+ // Get the first item from the `oneOf` | `anyOf` array
202
+ const firstOneOfItem = discriminateSchema[0];
190
203
  // Return an example for the first item
191
204
  return getExampleFromSchema(firstOneOfItem, options, level + 1);
192
205
  }
@@ -7,5 +7,5 @@ import type { BaseParameter, TransformedOperation } from '@scalar/types/legacy';
7
7
  * - OpenAPI 3.x: Possible values are “query”, “header”, “path” or “cookie”.
8
8
  * - Swagger 2.0: Possible values are "query", "header", "path", "formData" or "body".
9
9
  */
10
- export declare function getParametersFromOperation(operation: TransformedOperation, where: 'query' | 'header' | 'path' | 'cookie' | 'formData' | 'body', requiredOnly?: boolean): BaseParameter[];
10
+ export declare function getParametersFromOperation(operation: Omit<TransformedOperation, 'httpVerb'>, where: 'query' | 'header' | 'path' | 'cookie' | 'formData' | 'body', requiredOnly?: boolean): BaseParameter[];
11
11
  //# sourceMappingURL=getParametersFromOperation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,oBAAoB,EAC/B,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,CAkCjB"}
1
+ {"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,CAkCjB"}
@@ -31,13 +31,14 @@ function getParametersFromOperation(operation, where, requiredOnly = true) {
31
31
  enabled: parameter.required ?? false,
32
32
  }));
33
33
  return params.sort((a, b) => {
34
- if (a.required && !b.required) {
35
- return -1; // Move a up if a is required and b is not
36
- }
37
- else if (!a.required && b.required) {
38
- return 1; // Move b up if b is required and a is not
39
- }
40
- return 0; // Keep original order if both have the same required status
34
+ // Move a up if a is required and b is not
35
+ if (a.required && !b.required)
36
+ return -1;
37
+ // Move b up if b is required and a is not
38
+ if (!a.required && b.required)
39
+ return 1;
40
+ // Keep original order if both have the same required status
41
+ return 0;
41
42
  });
42
43
  }
43
44
 
@@ -1,49 +1,21 @@
1
- import type { ContentType, TransformedOperation } from '@scalar/types/legacy';
1
+ import type { TransformedOperation } from '@scalar/types/legacy';
2
+ declare const mimeTypes: readonly ["application/json", "application/octet-stream", "application/x-www-form-urlencoded", "application/xml", "multipart/form-data", "text/plain"];
2
3
  /**
3
4
  * Get the request body from the operation.
4
5
  */
5
- export declare function getRequestBodyFromOperation(operation: TransformedOperation, selectedExampleKey?: string | number): {
6
- postData: {
7
- mimeType: string;
8
- text: string;
9
- params?: undefined;
10
- };
11
- headers?: undefined;
12
- } | {
13
- postData: {
14
- mimeType: string;
15
- params: {
16
- name: string;
17
- value: string | number | Record<string, any>;
18
- }[];
19
- text?: undefined;
20
- };
21
- headers?: undefined;
22
- } | {
23
- postData: undefined;
24
- headers?: undefined;
25
- } | {
26
- headers: {
27
- name: string;
28
- value: ContentType;
29
- }[];
30
- postData: {
31
- mimeType: string;
32
- text: any;
33
- params?: undefined;
34
- };
35
- } | {
36
- headers: {
6
+ export declare function getRequestBodyFromOperation(operation: Omit<TransformedOperation, 'httpVerb'>, selectedExampleKey?: string | number): {
7
+ headers?: {
37
8
  name: string;
38
- value: ContentType;
9
+ value: string;
39
10
  }[];
40
- postData: {
41
- mimeType: string;
42
- params: {
11
+ body?: {
12
+ mimeType: (typeof mimeTypes)[number];
13
+ text?: string;
14
+ params?: {
43
15
  name: string;
44
- value: any;
16
+ value?: string;
45
17
  }[];
46
- text?: undefined;
47
18
  };
48
- } | undefined;
19
+ } | null;
20
+ export {};
49
21
  //# sourceMappingURL=getRequestBodyFromOperation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestBodyFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestBodyFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAgC7E;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,oBAAoB,EAC/B,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAnB9B,MAAM;mBACL,GAAG;;;;cAiOX"}
1
+ {"version":3,"file":"getRequestBodyFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestBodyFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAgC7E,QAAA,MAAM,SAAS,wJAOL,CAAA;AAEV;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,GACnC;IACD,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC3C,IAAI,CAAC,EAAE;QACL,QAAQ,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;QACpC,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,MAAM,CAAC,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,KAAK,CAAC,EAAE,MAAM,CAAA;SACf,EAAE,CAAA;KACJ,CAAA;CACF,GAAG,IAAI,CAgNP"}
@@ -17,23 +17,28 @@ function getParamsFromObject(obj, prefix = '') {
17
17
  return [{ name: newKey, value }];
18
18
  });
19
19
  }
20
+ // Define all supported mime types
21
+ const mimeTypes = [
22
+ 'application/json',
23
+ 'application/octet-stream',
24
+ 'application/x-www-form-urlencoded',
25
+ 'application/xml',
26
+ 'multipart/form-data',
27
+ 'text/plain',
28
+ ];
20
29
  /**
21
30
  * Get the request body from the operation.
22
31
  */
23
32
  function getRequestBodyFromOperation(operation, selectedExampleKey) {
24
- // Define all supported mime types
25
- const mimeTypes = [
26
- 'application/json',
27
- 'application/octet-stream',
28
- 'application/x-www-form-urlencoded',
29
- 'application/xml',
30
- 'multipart/form-data',
31
- 'text/plain',
32
- ];
33
33
  // Get the content object from the operation
34
34
  const originalContent = operation.information?.requestBody?.content;
35
35
  const content = normalizeMimeTypeObject(originalContent);
36
- // Find the first mime type that is supported
36
+ /**
37
+ * Find the first mime type that is supported
38
+ *
39
+ * TODO: This is very fragile. There needs to be significantly more support for
40
+ * vendor specific content types (like application/vnd.github+json)
41
+ */
37
42
  const mimeType = mimeTypes.find((currentMimeType) => !!content?.[currentMimeType]);
38
43
  /** Examples */
39
44
  const examples = content?.['application/json']?.examples;
@@ -41,7 +46,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
41
46
  const selectedExample = (examples ?? {})?.[selectedExampleKey ?? Object.keys(examples ?? {})[0]];
42
47
  if (selectedExample) {
43
48
  return {
44
- postData: {
49
+ body: {
45
50
  mimeType: 'application/json',
46
51
  text: prettyPrintJson(selectedExample?.value),
47
52
  },
@@ -58,7 +63,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
58
63
  const bodyParameters = getParametersFromOperation(operation, 'body', false);
59
64
  if (bodyParameters.length > 0) {
60
65
  return {
61
- postData: {
66
+ body: {
62
67
  mimeType: 'application/json',
63
68
  text: prettyPrintJson(bodyParameters[0].value),
64
69
  },
@@ -83,20 +88,26 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
83
88
  const formDataParameters = getParametersFromOperation(operation, 'formData', false);
84
89
  if (formDataParameters.length > 0) {
85
90
  return {
86
- postData: {
91
+ body: {
87
92
  mimeType: 'application/x-www-form-urlencoded',
88
93
  params: formDataParameters.map((parameter) => ({
89
94
  name: parameter.name,
90
- value: parameter.value,
95
+ /**
96
+ * TODO: This value MUST be a string
97
+ * Figure out why this is not always a string
98
+ *
99
+ * JSON.stringify is a TEMPORARY fix
100
+ */
101
+ value: typeof parameter.value === 'string'
102
+ ? parameter.value
103
+ : JSON.stringify(parameter.value),
91
104
  })),
92
105
  },
93
106
  };
94
107
  }
95
108
  // If no mime type is supported, exit early
96
109
  if (!mimeType) {
97
- return {
98
- postData: undefined,
99
- };
110
+ return null;
100
111
  }
101
112
  // Get the request body object for the mime type
102
113
  const requestBodyObject = content?.[mimeType];
@@ -122,7 +133,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
122
133
  const body = example ?? exampleFromSchema;
123
134
  return {
124
135
  headers,
125
- postData: {
136
+ body: {
126
137
  mimeType: mimeType,
127
138
  text: typeof body === 'string' ? body : JSON.stringify(body, null, 2),
128
139
  },
@@ -139,7 +150,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
139
150
  : null;
140
151
  return {
141
152
  headers,
142
- postData: {
153
+ body: {
143
154
  mimeType: mimeType,
144
155
  text: example ?? json2xml(exampleFromSchema, ' '),
145
156
  },
@@ -149,7 +160,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
149
160
  if (mimeType === 'application/octet-stream') {
150
161
  return {
151
162
  headers,
152
- postData: {
163
+ body: {
153
164
  mimeType: mimeType,
154
165
  text: 'BINARY',
155
166
  },
@@ -166,7 +177,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
166
177
  : null;
167
178
  return {
168
179
  headers,
169
- postData: {
180
+ body: {
170
181
  mimeType: mimeType,
171
182
  text: example ?? exampleFromSchema ?? '',
172
183
  },
@@ -184,13 +195,13 @@ function getRequestBodyFromOperation(operation, selectedExampleKey) {
184
195
  : null;
185
196
  return {
186
197
  headers,
187
- postData: {
198
+ body: {
188
199
  mimeType: mimeType,
189
200
  params: getParamsFromObject(example ?? exampleFromSchema ?? {}),
190
201
  },
191
202
  };
192
203
  }
193
- return undefined;
204
+ return null;
194
205
  }
195
206
 
196
207
  export { getRequestBodyFromOperation };
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAK7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA6D5B,CAAA"}
1
+ {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAK7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA4D5B,CAAA"}
@@ -34,12 +34,11 @@ const getRequestFromOperation = (operation, options, selectedExampleKey) => {
34
34
  return {
35
35
  method: operation.httpVerb.toUpperCase(),
36
36
  path,
37
+ postData: requestBody?.body,
37
38
  headers: [
38
39
  ...getParametersFromOperation(operation, 'header', options?.requiredOnly),
39
40
  ...(requestBody?.headers ?? []),
40
41
  ],
41
- // @ts-expect-error Sorry, something is off here and I don’t get it.
42
- postData: requestBody?.postData,
43
42
  queryString: getParametersFromOperation(operation, 'query', options?.requiredOnly),
44
43
  cookies: getParametersFromOperation(operation, 'cookie', options?.requiredOnly),
45
44
  };
@@ -0,0 +1,4 @@
1
+ import type { Server } from '../entities/spec/server.js';
2
+ /** Retrieve example values for server variables */
3
+ export declare const getServerVariableExamples: (server: Server) => Record<string, string[]>;
4
+ //# sourceMappingURL=getServerVariableExamples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getServerVariableExamples.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getServerVariableExamples.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,mDAAmD;AACnD,eAAO,MAAM,yBAAyB,WAAY,MAAM,6BAUvD,CAAA"}
@@ -0,0 +1,12 @@
1
+ /** Retrieve example values for server variables */
2
+ const getServerVariableExamples = (server) => {
3
+ const examples = {};
4
+ if (server.variables) {
5
+ for (const [key, variable] of Object.entries(server.variables)) {
6
+ examples[key] = variable.enum?.filter((v) => typeof v === 'string') ?? [variable.default];
7
+ }
8
+ }
9
+ return examples;
10
+ };
11
+
12
+ export { getServerVariableExamples };
@@ -2,4 +2,5 @@ export * from './getExampleFromSchema.js';
2
2
  export * from './getParametersFromOperation.js';
3
3
  export * from './getRequestBodyFromOperation.js';
4
4
  export * from './getRequestFromOperation.js';
5
+ export * from './getServerVariableExamples.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spec-getters/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spec-getters/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA"}
@@ -2,3 +2,4 @@ export { getExampleFromSchema } from './getExampleFromSchema.js';
2
2
  export { getParametersFromOperation } from './getParametersFromOperation.js';
3
3
  export { getRequestBodyFromOperation } from './getRequestBodyFromOperation.js';
4
4
  export { getRequestFromOperation } from './getRequestFromOperation.js';
5
+ export { getServerVariableExamples } from './getServerVariableExamples.js';
@@ -0,0 +1,68 @@
1
+ import { type Collection, type Request } from '../entities/spec/index.js';
2
+ export declare function exportSpecFromWorkspace({ collection, requests, }: {
3
+ collection: Collection;
4
+ requests: Record<string, Request>;
5
+ }): {
6
+ type: "collection";
7
+ uid: string;
8
+ children: string[];
9
+ openapi: string;
10
+ security: Record<string, string[]>[];
11
+ securitySchemes: string[];
12
+ selectedServerUid: string;
13
+ servers: string[];
14
+ requests: string[];
15
+ tags: string[];
16
+ auth: Record<string, {
17
+ type: "apiKey";
18
+ value: string;
19
+ name: string;
20
+ } | {
21
+ type: "http";
22
+ username: string;
23
+ password: string;
24
+ token: string;
25
+ } | {
26
+ type: "oauth-implicit";
27
+ token: string;
28
+ } | {
29
+ type: "oauth-password";
30
+ username: string;
31
+ password: string;
32
+ token: string;
33
+ clientSecret: string;
34
+ } | {
35
+ type: "oauth-clientCredentials";
36
+ token: string;
37
+ clientSecret: string;
38
+ } | {
39
+ type: "oauth-authorizationCode";
40
+ token: string;
41
+ clientSecret: string;
42
+ }>;
43
+ externalDocs?: {
44
+ url: string;
45
+ description?: string | undefined;
46
+ } | undefined;
47
+ jsonSchemaDialect?: string | undefined;
48
+ info?: {
49
+ title: string;
50
+ version: string;
51
+ description?: string | undefined;
52
+ summary?: string | undefined;
53
+ termsOfService?: string | undefined;
54
+ contact?: {
55
+ name?: string | undefined;
56
+ url?: string | undefined;
57
+ email?: string | undefined;
58
+ } | undefined;
59
+ license?: {
60
+ name: string;
61
+ identifier?: string | undefined;
62
+ url?: string | undefined;
63
+ } | undefined;
64
+ } | undefined;
65
+ components?: Record<string, unknown> | undefined;
66
+ webhooks?: Record<string, unknown> | undefined;
67
+ };
68
+ //# sourceMappingURL=export-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/export-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EAEb,MAAM,iBAAiB,CAAA;AAMxB,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,QAAQ,GACT,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEA"}
@@ -1,72 +1,24 @@
1
- import { type Request } from '../entities/workspace/spec/index.js';
2
- import type { Spec } from '@scalar/types/legacy';
1
+ import { type Collection, type Request, type RequestExample, type Server, type Tag } from '../entities/spec/index.js';
2
+ import { type SecurityScheme } from '../entities/spec/security.js';
3
3
  import type { UnknownObject } from '@scalar/types/utils';
4
- /** Import an OpenAPI spec file and convert it to workspace entities */
5
- export declare const importSpecToWorkspace: (spec: string | UnknownObject, overloadServers?: Spec["servers"]) => Promise<{
6
- tags: {
7
- name: string;
8
- description?: string | undefined;
9
- }[];
10
- folders: {
11
- uid: string;
12
- name: string;
13
- childUids: string[];
14
- description?: string | undefined;
15
- }[];
16
- servers: {
17
- uid: string;
18
- url: string;
19
- description?: string | undefined;
20
- variables?: Record<string, {
21
- default: string;
22
- uid: string;
23
- value?: string | undefined;
24
- description?: string | undefined;
25
- enum?: string[] | undefined;
26
- }> | null | undefined;
27
- }[];
4
+ /**
5
+ * Import an OpenAPI spec file and convert it to workspace entities
6
+ *
7
+ * We will aim to keep the entities as close to the specification as possible
8
+ * to leverage bi-directional translation. Where entities are able to be
9
+ * created and used at various levels we will index via the uids to create
10
+ * the relationships
11
+ */
12
+ export declare function importSpecToWorkspace(spec: string | UnknownObject): Promise<{
13
+ error: false;
14
+ collection: Collection;
28
15
  requests: Request[];
29
- collection: {
30
- uid: string;
31
- spec: {
32
- openapi: string;
33
- security: Record<string, string[]>[];
34
- serverUids: string[];
35
- tags: {
36
- name: string;
37
- description?: string | undefined;
38
- externalDocs?: {
39
- url: string;
40
- description?: string | undefined;
41
- } | undefined;
42
- }[];
43
- externalDocs?: {
44
- url: string;
45
- description?: string | undefined;
46
- } | undefined;
47
- info?: {
48
- title: string;
49
- version: string;
50
- description?: string | undefined;
51
- summary?: string | undefined;
52
- termsOfService?: string | undefined;
53
- contact?: {
54
- name?: string | undefined;
55
- url?: string | undefined;
56
- email?: string | undefined;
57
- } | undefined;
58
- license?: {
59
- name: string;
60
- identifier?: string | undefined;
61
- url?: string | undefined;
62
- } | undefined;
63
- } | undefined;
64
- };
65
- securitySchemeDict: Record<string, string>;
66
- selectedServerUid: string;
67
- childUids: string[];
68
- };
69
- components: any;
70
- securityDefinitions: any;
16
+ examples: RequestExample[];
17
+ servers: Server[];
18
+ tags: Tag[];
19
+ securitySchemes: SecurityScheme[];
20
+ } | {
21
+ error: true;
22
+ importWarnings: string[];
71
23
  }>;
72
24
  //# sourceMappingURL=import-spec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,2BAA2B,CAAA;AAKvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AASxD,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,SAC1B,MAAM,GAAG,aAAa,oBACV,IAAI,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsKlC,CAAA"}
1
+ {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAOT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAKjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAiCxD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,GAAG,aAAa,GAC3B,OAAO,CACN;IACE,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CAwOA"}