@scalar/oas-utils 0.2.103 → 0.2.105

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 (30) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/entities/spec/index.js +1 -1
  3. package/dist/entities/spec/request-examples.d.ts +267 -55
  4. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  5. package/dist/entities/spec/request-examples.js +43 -12
  6. package/dist/entities/spec/spec-objects.js +1 -1
  7. package/dist/entities/workspace/workspace.d.ts +19 -0
  8. package/dist/entities/workspace/workspace.d.ts.map +1 -1
  9. package/dist/entities/workspace/workspace.js +11 -0
  10. package/dist/helpers/ensure-protocol.d.ts.map +1 -1
  11. package/dist/helpers/ensure-protocol.js +1 -2
  12. package/dist/helpers/fetchWithProxyFallback.d.ts +1 -1
  13. package/dist/helpers/fetchWithProxyFallback.d.ts.map +1 -1
  14. package/dist/helpers/merge-urls.d.ts +1 -1
  15. package/dist/helpers/merge-urls.d.ts.map +1 -1
  16. package/dist/helpers/merge-urls.js +17 -10
  17. package/dist/helpers/redirectToProxy.d.ts.map +1 -1
  18. package/dist/helpers/redirectToProxy.js +1 -5
  19. package/dist/helpers/regexHelpers.d.ts +3 -1
  20. package/dist/helpers/regexHelpers.d.ts.map +1 -1
  21. package/dist/helpers/regexHelpers.js +4 -2
  22. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  23. package/dist/migrations/v-2.5.0/migration.js +11 -0
  24. package/dist/spec-getters/getRequestBodyFromOperation.d.ts +4 -10
  25. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  26. package/dist/spec-getters/getRequestBodyFromOperation.js +29 -57
  27. package/dist/transforms/import-spec.d.ts +1 -3
  28. package/dist/transforms/import-spec.d.ts.map +1 -1
  29. package/dist/transforms/import-spec.js +25 -7
  30. package/package.json +9 -11
@@ -1 +1 @@
1
- {"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../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AAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;;;;;;;;;;;;;EA8D9D;AAKD,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;;EAuD1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CAmHhB"}
@@ -13,7 +13,8 @@ import { getServerVariableExamples } from '../../spec-getters/getServerVariableE
13
13
  * The request schema should be stored in the request and any
14
14
  * parameters should be validated against that
15
15
  */
16
- const requestExampleParametersSchema = z.object({
16
+ const requestExampleParametersSchema = z
17
+ .object({
17
18
  key: z.string().default(''),
18
19
  value: z.coerce.string().default(''),
19
20
  enabled: z.boolean().default(true),
@@ -22,12 +23,33 @@ const requestExampleParametersSchema = z.object({
22
23
  required: z.boolean().optional(),
23
24
  enum: z.array(z.string()).optional(),
24
25
  examples: z.array(z.string()).optional(),
25
- type: z.string().optional(),
26
+ type: z
27
+ .union([
28
+ // 'string'
29
+ z.string(),
30
+ // ['string', 'null']
31
+ z.array(z.string()),
32
+ ])
33
+ .optional(),
26
34
  format: z.string().optional(),
27
35
  minimum: z.number().optional(),
28
36
  maximum: z.number().optional(),
29
37
  default: z.any().optional(),
30
38
  nullable: z.boolean().optional(),
39
+ })
40
+ // set nullable: to true if type is ['string', 'null']
41
+ .transform((data) => {
42
+ // type: ['string', 'null'] -> nullable: true
43
+ if (Array.isArray(data.type) && data.type.includes('null')) {
44
+ data = { ...data, nullable: true };
45
+ }
46
+ // Hey, if it’s just one value and 'null', we can make it a string and ditch the 'null'.
47
+ if (Array.isArray(data.type) &&
48
+ data.type.length === 2 &&
49
+ data.type.includes('null')) {
50
+ data = { ...data, type: data.type.find((item) => item !== 'null') };
51
+ }
52
+ return data;
31
53
  });
32
54
  /** Convert the array of parameters to an object keyed by the parameter name */
33
55
  function parameterArrayToObject(params) {
@@ -309,42 +331,51 @@ function createExampleFromRequest(request, name, server) {
309
331
  requestBody: request.requestBody,
310
332
  },
311
333
  });
312
- if (requestBody?.body?.mimeType === 'application/json') {
334
+ if (requestBody?.mimeType === 'application/json') {
313
335
  body.activeBody = 'raw';
314
336
  body.raw = {
315
337
  encoding: 'json',
316
- value: requestBody.body.text ?? JSON.stringify({}),
338
+ value: requestBody.text ?? JSON.stringify({}),
317
339
  };
318
340
  }
319
- if (requestBody?.body?.mimeType === 'application/xml') {
341
+ if (requestBody?.mimeType === 'application/xml') {
320
342
  body.activeBody = 'raw';
321
343
  body.raw = {
322
344
  encoding: 'xml',
323
- value: requestBody.body.text ?? '',
345
+ value: requestBody.text ?? '',
324
346
  };
325
347
  }
326
348
  /**
327
349
  * TODO: Are we loading example files from somewhere based on the spec?
328
350
  * How are we handling the body values
329
351
  */
330
- if (requestBody?.body?.mimeType === 'application/octet-stream') {
352
+ if (requestBody?.mimeType === 'application/octet-stream') {
331
353
  body.activeBody = 'binary';
332
354
  body.binary = undefined;
333
355
  }
334
- if (requestBody?.body?.mimeType === 'application/x-www-form-urlencoded' ||
335
- requestBody?.body?.mimeType === 'multipart/form-data') {
356
+ if (requestBody?.mimeType === 'application/x-www-form-urlencoded' ||
357
+ requestBody?.mimeType === 'multipart/form-data') {
336
358
  body.activeBody = 'formData';
337
359
  body.formData = {
338
- encoding: requestBody.body.mimeType === 'application/x-www-form-urlencoded'
360
+ encoding: requestBody.mimeType === 'application/x-www-form-urlencoded'
339
361
  ? 'urlencoded'
340
362
  : 'form-data',
341
- value: (requestBody.body.params || []).map((param) => ({
363
+ value: (requestBody.params || []).map((param) => ({
342
364
  key: param.name,
343
365
  value: param.value || '',
344
366
  enabled: true,
345
367
  })),
346
368
  };
347
369
  }
370
+ // Add the content-type header if it doesn't exist
371
+ if (requestBody?.mimeType &&
372
+ !parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')) {
373
+ parameters.headers.push({
374
+ key: 'Content-Type',
375
+ value: requestBody.mimeType,
376
+ enabled: true,
377
+ });
378
+ }
348
379
  }
349
380
  const serverVariables = server ? getServerVariableExamples(server) : {};
350
381
  // safe parse the example
@@ -363,4 +394,4 @@ function createExampleFromRequest(request, name, server) {
363
394
  return example;
364
395
  }
365
396
 
366
- export { convertExampleToXScalar, createExampleFromRequest, createParamInstance, exampleBodyMime, exampleRequestBodyEncoding, exampleRequestBodySchema, requestExampleParametersSchema, requestExampleSchema, xScalarExampleBodySchema, xScalarExampleSchema, xScalarFileValueSchema, xScalarFormDataValue };
397
+ export { convertExampleToXScalar, createExampleFromRequest, createParamInstance, exampleBodyMime, exampleRequestBodyEncoding, exampleRequestBodySchema, parameterArrayToObject, requestExampleParametersSchema, requestExampleSchema, xScalarExampleBodySchema, xScalarExampleSchema, xScalarFileValueSchema, xScalarFormDataValue };
@@ -40,7 +40,7 @@ const oasContactSchema = z.object({
40
40
  */
41
41
  const oasInfoSchema = z.object({
42
42
  /** REQUIRED. The title of the API. */
43
- title: z.string().optional().default('OpenAPI Spec'),
43
+ title: z.string().optional().default('API'),
44
44
  /** A short summary of the API. */
45
45
  summary: z.string().optional(),
46
46
  /** A description of the API. CommonMark syntax MAY be used for rich text representation. */
@@ -55,6 +55,17 @@ export declare const workspaceSchema: z.ZodObject<{
55
55
  proxyUrl: z.ZodOptional<z.ZodString>;
56
56
  /** Workspace level theme, we might move this to user level later */
57
57
  themeId: z.ZodDefault<z.ZodOptional<z.ZodEnum<["alternate", "default", "moon", "purple", "solarized", "bluePlanet", "deepSpace", "saturn", "kepler", "elysiajs", "fastify", "mars", "none"]>>>;
58
+ /** Currently selected snippet client */
59
+ selectedHttpClient: z.ZodDefault<z.ZodOptional<z.ZodObject<{
60
+ targetKey: z.ZodString;
61
+ clientKey: z.ZodString;
62
+ }, "strip", z.ZodTypeAny, {
63
+ targetKey: string;
64
+ clientKey: string;
65
+ }, {
66
+ targetKey: string;
67
+ clientKey: string;
68
+ }>>>;
58
69
  }, "strip", z.ZodTypeAny, {
59
70
  uid: string;
60
71
  name: string;
@@ -64,6 +75,10 @@ export declare const workspaceSchema: z.ZodObject<{
64
75
  activeEnvironmentId: string;
65
76
  cookies: string[];
66
77
  themeId: "default" | "alternate" | "moon" | "purple" | "solarized" | "bluePlanet" | "deepSpace" | "saturn" | "kepler" | "elysiajs" | "fastify" | "mars" | "none";
78
+ selectedHttpClient: {
79
+ targetKey: string;
80
+ clientKey: string;
81
+ };
67
82
  hotKeyConfig?: {
68
83
  modifiers: ("Meta" | "Control" | "Shift" | "Alt" | "default")[];
69
84
  hotKeys?: Partial<Record<"" | "/" | "Space" | "Backspace" | "Tab" | "Enter" | "Escape" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "End" | "Home" | "PageDown" | "PageUp" | "Delete" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "*" | "+" | "-" | "." | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | ";" | "=" | "," | "`" | "[" | "\\" | "]", {
@@ -89,6 +104,10 @@ export declare const workspaceSchema: z.ZodObject<{
89
104
  cookies?: string[] | undefined;
90
105
  proxyUrl?: string | undefined;
91
106
  themeId?: "default" | "alternate" | "moon" | "purple" | "solarized" | "bluePlanet" | "deepSpace" | "saturn" | "kepler" | "elysiajs" | "fastify" | "mars" | "none" | undefined;
107
+ selectedHttpClient?: {
108
+ targetKey: string;
109
+ clientKey: string;
110
+ } | undefined;
92
111
  }>;
93
112
  /** The base scalar workspace */
94
113
  export type Workspace = z.infer<typeof workspaceSchema>;
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/entities/workspace/workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AASvB,QAAA,MAAM,SAAS,yIAAoD,CAAA;AAEnE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAA;AAEvD,QAAA,MAAM,OAAO;;;;;;;;;GAMZ,CAAA;AACD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAA;AASlD,eAAO,MAAM,eAAe;;;IAG1B,4BAA4B;;IAE5B,uDAAuD;;IAEvD,wDAAwD;;IAExD,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;IAExB,iDAAiD;;IAEjD,mDAAmD;;IAEnD,gEAAgE;;IAEhE,oEAAoE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEpE,CAAA;AAEF,gCAAgC;AAChC,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AACvD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA"}
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/entities/workspace/workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AASvB,QAAA,MAAM,SAAS,yIAAoD,CAAA;AAEnE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAA;AAEvD,QAAA,MAAM,OAAO;;;;;;;;;GAMZ,CAAA;AACD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAA;AASlD,eAAO,MAAM,eAAe;;;IAG1B,4BAA4B;;IAE5B,uDAAuD;;IAEvD,wDAAwD;;IAExD,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;IAExB,iDAAiD;;IAEjD,mDAAmD;;IAEnD,gEAAgE;;IAEhE,oEAAoE;;IAEpE,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWxC,CAAA;AAEF,gCAAgC;AAChC,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AACvD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA"}
@@ -37,6 +37,17 @@ const workspaceSchema = z.object({
37
37
  proxyUrl: z.string().optional(),
38
38
  /** Workspace level theme, we might move this to user level later */
39
39
  themeId: z.enum(themeIds).optional().default('default'),
40
+ /** Currently selected snippet client */
41
+ selectedHttpClient: z
42
+ .object({
43
+ targetKey: z.string(),
44
+ clientKey: z.string(),
45
+ })
46
+ .optional()
47
+ .default({
48
+ targetKey: 'shell',
49
+ clientKey: 'curl',
50
+ }),
40
51
  });
41
52
 
42
53
  export { workspaceSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"ensure-protocol.d.ts","sourceRoot":"","sources":["../../src/helpers/ensure-protocol.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMlD"}
1
+ {"version":3,"file":"ensure-protocol.d.ts","sourceRoot":"","sources":["../../src/helpers/ensure-protocol.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKlD"}
@@ -2,9 +2,8 @@ import { REGEX } from './regexHelpers.js';
2
2
 
3
3
  /** Ensure URL has a protocol prefix */
4
4
  function ensureProtocol(url) {
5
- if (REGEX.PATH.test(url) || REGEX.PROTOCOL.test(url)) {
5
+ if (REGEX.PROTOCOL.test(url))
6
6
  return url;
7
- }
8
7
  // Default to http if no protocol is specified
9
8
  return `http://${url.replace(/^\//, '')}`;
10
9
  }
@@ -1,5 +1,5 @@
1
1
  export type FetchWithProxyFallbackOptions = {
2
- proxy?: string;
2
+ proxy: string | undefined;
3
3
  /**
4
4
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"fetchWithProxyFallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchWithProxyFallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,MAAM,EACX,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAwBhD"}
1
+ {"version":3,"file":"fetchWithProxyFallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchWithProxyFallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,MAAM,EACX,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAwBhD"}
@@ -11,5 +11,5 @@ export declare const combineUrlAndPath: (url: string, path: string) => string;
11
11
  * also optionally merges query params if you include urlSearchParams
12
12
  * This was re-written without using URL to support variables in the scheme
13
13
  */
14
- export declare const mergeUrls: (url: string, path: string, urlParams?: URLSearchParams) => string;
14
+ export declare const mergeUrls: (url: string, path: string, urlParams?: URLSearchParams, disableOriginPrefix?: boolean) => string;
15
15
  //# sourceMappingURL=merge-urls.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-urls.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-urls.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,cACjB,eAAe,EAAE,KAC3B,eA6BF,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAS,MAAM,QAAQ,MAAM,WAQ1D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,QACf,MAAM,QACL,MAAM,cACD,eAAe,WAiC3B,CAAA"}
1
+ {"version":3,"file":"merge-urls.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-urls.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,cACjB,eAAe,EAAE,KAC3B,eA6BF,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAS,MAAM,QAAQ,MAAM,WAM1D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,QACf,MAAM,QACL,MAAM,cACD,eAAe,0CAuC3B,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { REGEX } from './regexHelpers.js';
1
2
  import { ensureProtocol } from './ensure-protocol.js';
2
3
  import { isRelativePath } from './redirectToProxy.js';
3
4
 
@@ -35,23 +36,26 @@ const mergeSearchParams = (...params) => {
35
36
  const combineUrlAndPath = (url, path) => {
36
37
  if (!path || url === path)
37
38
  return url.trim();
38
- // Remove trailing slash from url and leading slash from path
39
- const cleanBase = url.replace(/\/+$/, '').trim();
40
- const cleanPath = path.replace(/^\/+/, '').trim();
41
- return `${cleanBase}/${cleanPath}`;
39
+ if (!url)
40
+ return path.trim();
41
+ return `${url.trim()}/${path.trim()}`.replace(REGEX.MULTIPLE_SLASHES, '/');
42
42
  };
43
43
  /**
44
44
  * Creates a URL from the path and server
45
45
  * also optionally merges query params if you include urlSearchParams
46
46
  * This was re-written without using URL to support variables in the scheme
47
47
  */
48
- const mergeUrls = (url, path, urlParams = new URLSearchParams()) => {
48
+ const mergeUrls = (url, path, urlParams = new URLSearchParams(),
49
+ /** To disable prefixing the url with the origin or a scheme*/
50
+ disableOriginPrefix = false) => {
49
51
  // Extract and merge all query params
50
52
  if (url && (!isRelativePath(url) || typeof window !== 'undefined')) {
51
- /** Prefix the url with the origin if it is relative */
52
- const base = isRelativePath(url)
53
- ? combineUrlAndPath(window.location.origin, url)
54
- : ensureProtocol(url);
53
+ /** Prefix the url with the origin if it is relative and we wish to */
54
+ const base = disableOriginPrefix
55
+ ? url
56
+ : isRelativePath(url)
57
+ ? combineUrlAndPath(window.location.origin, url)
58
+ : ensureProtocol(url);
55
59
  // Extract search params from base URL if any
56
60
  const [baseUrl = '', baseQuery] = base.split('?');
57
61
  const baseParams = new URLSearchParams(baseQuery || '');
@@ -66,7 +70,10 @@ const mergeUrls = (url, path, urlParams = new URLSearchParams()) => {
66
70
  const search = mergedSearchParams.toString();
67
71
  return search ? `${mergedUrl}?${search}` : mergedUrl;
68
72
  }
69
- return url;
73
+ else if (path) {
74
+ return combineUrlAndPath(url, path);
75
+ }
76
+ return '';
70
77
  };
71
78
 
72
79
  export { combineUrlAndPath, mergeSearchParams, mergeUrls };
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAkBzC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAWpE"}
1
+ {"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAWpE"}
@@ -16,11 +16,7 @@ function redirectToProxy(proxy, url) {
16
16
  }
17
17
  /** Check if the URL is relative or if it's a domain without protocol */
18
18
  const isRelativePath = (url) => {
19
- // Absolute URLs start with http:// or https://
20
- if (url.startsWith('http://') || url.startsWith('https://')) {
21
- return false;
22
- }
23
- // Allow other protocols such as file://
19
+ // Allow http:// https:// and other protocols such as file://
24
20
  if (REGEX.PROTOCOL.test(url)) {
25
21
  return false;
26
22
  }
@@ -1,6 +1,8 @@
1
1
  export declare const REGEX: {
2
- /** Checks if the url starts with a protocol like file:// including {variable}:// */
2
+ /** Checks for a valid scheme */
3
3
  readonly PROTOCOL: RegExp;
4
+ /** Finds multiple slashes after the scheme to replace with a single slash */
5
+ readonly MULTIPLE_SLASHES: RegExp;
4
6
  readonly VARIABLES: RegExp;
5
7
  readonly PATH: RegExp;
6
8
  readonly TEMPLATE_VARIABLE: RegExp;
@@ -1 +1 @@
1
- {"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;IAChB,oFAAoF;;;;;CAK5E,CAAA"}
1
+ {"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;IAChB,gCAAgC;;IAEhC,6EAA6E;;;;;CAKrE,CAAA"}
@@ -1,6 +1,8 @@
1
1
  const REGEX = {
2
- /** Checks if the url starts with a protocol like file:// including {variable}:// */
3
- PROTOCOL: /^[a-zA-Z{}][a-zA-Z0-9+.{}-]*:\/\//,
2
+ /** Checks for a valid scheme */
3
+ PROTOCOL: /^(?:https?|ftp|file|mailto|tel|data|wss?)*:\/\//,
4
+ /** Finds multiple slashes after the scheme to replace with a single slash */
5
+ MULTIPLE_SLASHES: /(?<!:)\/{2,}/g,
4
6
  VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,
5
7
  PATH: /(?:{)([^{}]+)}(?!})/g,
6
8
  TEMPLATE_VARIABLE: /{{\s*([^}\s]+?)\s*}}|{\s*([^}\s]+?)\s*}|:\b[\w.]+\b/g,
@@ -1 +1 @@
1
- {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.5.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SACpB,OAAO,CAAC,UAAU,KACvB,OAAO,CAAC,UAgEV,CAAA"}
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.5.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SACpB,OAAO,CAAC,UAAU,KACvB,OAAO,CAAC,UA8EV,CAAA"}
@@ -36,10 +36,21 @@ const migrate_v_2_5_0 = (data) => {
36
36
  };
37
37
  return acc;
38
38
  }, {});
39
+ const workspaces = Object.entries(data.workspaces || {}).reduce((acc, [key, workspace]) => {
40
+ acc[key] = {
41
+ ...workspace,
42
+ selectedHttpClient: {
43
+ targetKey: 'shell',
44
+ clientKey: 'curl',
45
+ },
46
+ };
47
+ return acc;
48
+ }, {});
39
49
  return {
40
50
  ...data,
41
51
  requestExamples,
42
52
  servers,
53
+ workspaces,
43
54
  };
44
55
  };
45
56
 
@@ -4,18 +4,12 @@ declare const mimeTypes: readonly ["application/json", "application/octet-stream
4
4
  * Get the request body from the operation.
5
5
  */
6
6
  export declare function getRequestBodyFromOperation(operation: Omit<TransformedOperation, 'httpVerb'>, selectedExampleKey?: string | number, omitEmptyAndOptionalProperties?: boolean): {
7
- headers?: {
7
+ mimeType: (typeof mimeTypes)[number];
8
+ text?: string;
9
+ params?: {
8
10
  name: string;
9
- value: string;
11
+ value?: string;
10
12
  }[];
11
- body?: {
12
- mimeType: (typeof mimeTypes)[number];
13
- text?: string;
14
- params?: {
15
- name: string;
16
- value?: string;
17
- }[];
18
- };
19
13
  } | null;
20
14
  export {};
21
15
  //# 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,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,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;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,CA6MP"}
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,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,EAAE,CAAA;CACJ,GAAG,IAAI,CAkLP"}
@@ -39,17 +39,15 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
39
39
  * TODO: This is very fragile. There needs to be significantly more support for
40
40
  * vendor specific content types (like application/vnd.github+json)
41
41
  */
42
- const mimeType = mimeTypes.find((currentMimeType) => !!content?.[currentMimeType]);
42
+ const mimeType = mimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ?? 'application/json';
43
43
  /** Examples */
44
- const examples = content?.['application/json']?.examples;
44
+ const examples = content?.[mimeType]?.examples ?? content?.['application/json']?.examples;
45
45
  // Let’s use the first example
46
46
  const selectedExample = (examples ?? {})?.[selectedExampleKey ?? Object.keys(examples ?? {})[0]];
47
47
  if (selectedExample) {
48
48
  return {
49
- body: {
50
- mimeType: 'application/json',
51
- text: prettyPrintJson(selectedExample?.value),
52
- },
49
+ mimeType,
50
+ text: prettyPrintJson(selectedExample?.value),
53
51
  };
54
52
  }
55
53
  /**
@@ -63,10 +61,8 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
63
61
  const bodyParameters = getParametersFromOperation(operation, 'body', false);
64
62
  if (bodyParameters.length > 0) {
65
63
  return {
66
- body: {
67
- mimeType: 'application/json',
68
- text: prettyPrintJson(bodyParameters[0].value),
69
- },
64
+ mimeType: 'application/json',
65
+ text: prettyPrintJson(bodyParameters[0].value),
70
66
  };
71
67
  }
72
68
  /**
@@ -88,21 +84,19 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
88
84
  const formDataParameters = getParametersFromOperation(operation, 'formData', false);
89
85
  if (formDataParameters.length > 0) {
90
86
  return {
91
- body: {
92
- mimeType: 'application/x-www-form-urlencoded',
93
- params: formDataParameters.map((parameter) => ({
94
- name: parameter.name,
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),
104
- })),
105
- },
87
+ mimeType: 'application/x-www-form-urlencoded',
88
+ params: formDataParameters.map((parameter) => ({
89
+ name: parameter.name,
90
+ /**
91
+ * TODO: This value MUST be a string
92
+ * Figure out why this is not always a string
93
+ *
94
+ * JSON.stringify is a TEMPORARY fix
95
+ */
96
+ value: typeof parameter.value === 'string'
97
+ ? parameter.value
98
+ : JSON.stringify(parameter.value),
99
+ })),
106
100
  };
107
101
  }
108
102
  // If no mime type is supported, exit early
@@ -111,13 +105,6 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
111
105
  }
112
106
  // Get the request body object for the mime type
113
107
  const requestBodyObject = content?.[mimeType];
114
- // Define the appropriate Content-Type headers
115
- const headers = [
116
- {
117
- name: 'Content-Type',
118
- value: mimeType,
119
- },
120
- ];
121
108
  // Get example from operation
122
109
  const example = requestBodyObject?.example
123
110
  ? requestBodyObject?.example
@@ -132,11 +119,8 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
132
119
  : null;
133
120
  const body = example ?? exampleFromSchema;
134
121
  return {
135
- headers,
136
- body: {
137
- mimeType: mimeType,
138
- text: typeof body === 'string' ? body : JSON.stringify(body, null, 2),
139
- },
122
+ mimeType,
123
+ text: typeof body === 'string' ? body : JSON.stringify(body, null, 2),
140
124
  };
141
125
  }
142
126
  // XML
@@ -148,21 +132,15 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
148
132
  })
149
133
  : null;
150
134
  return {
151
- headers,
152
- body: {
153
- mimeType: mimeType,
154
- text: example ?? json2xml(exampleFromSchema, ' '),
155
- },
135
+ mimeType,
136
+ text: example ?? json2xml(exampleFromSchema, ' '),
156
137
  };
157
138
  }
158
139
  // Binary data
159
140
  if (mimeType === 'application/octet-stream') {
160
141
  return {
161
- headers,
162
- body: {
163
- mimeType: mimeType,
164
- text: 'BINARY',
165
- },
142
+ mimeType,
143
+ text: 'BINARY',
166
144
  };
167
145
  }
168
146
  // Plain text
@@ -174,11 +152,8 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
174
152
  })
175
153
  : null;
176
154
  return {
177
- headers,
178
- body: {
179
- mimeType: mimeType,
180
- text: example ?? exampleFromSchema ?? '',
181
- },
155
+ mimeType,
156
+ text: example ?? exampleFromSchema ?? '',
182
157
  };
183
158
  }
184
159
  // URL encoded data
@@ -191,11 +166,8 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
191
166
  })
192
167
  : null;
193
168
  return {
194
- headers,
195
- body: {
196
- mimeType: mimeType,
197
- params: getParamsFromObject(example ?? exampleFromSchema ?? {}),
198
- },
169
+ mimeType,
170
+ params: getParamsFromObject(example ?? exampleFromSchema ?? {}),
199
171
  };
200
172
  }
201
173
  return null;
@@ -16,9 +16,7 @@ export declare const parseSchema: (spec: string | UnknownObject, { shouldLoad }?
16
16
  errors: import("@scalar/openapi-parser").ErrorObject[];
17
17
  }>;
18
18
  /** Converts selected security requirements to uids */
19
- export declare const getSelectedSecuritySchemeUids: (securityRequirements: SelectedSecuritySchemeUids, authentication: {
20
- preferredSecurityScheme?: string | null;
21
- } | undefined, securitySchemeMap: Record<string, string>) => SelectedSecuritySchemeUids;
19
+ export declare const getSelectedSecuritySchemeUids: (securityRequirements: SelectedSecuritySchemeUids, authentication: ReferenceConfiguration["authentication"] | undefined, securitySchemeMap: Record<string, string>) => SelectedSecuritySchemeUids;
22
20
  export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers'> & {
23
21
  /** Sets the preferred security scheme on the collection instead of the requests */
24
22
  setCollectionSecurity?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAWjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAChB,MAAM,GAAG,aAAa;;;IAuC1B;;;OAGG;YAC8C,WAAW,CAAC,QAAQ;;EAGxE,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,6BAA6B,yBAClB,0BAA0B,kBAChC;IAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GA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EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC5B,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,CA6UA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAM,GACpE,MAAM,EAAE,CA8CV"}
@@ -52,14 +52,31 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
52
52
  };
53
53
  /** Converts selected security requirements to uids */
54
54
  const getSelectedSecuritySchemeUids = (securityRequirements, authentication, securitySchemeMap) => {
55
- const name = authentication?.preferredSecurityScheme &&
56
- securityRequirements.includes(authentication.preferredSecurityScheme)
57
- ? authentication.preferredSecurityScheme
58
- : securityRequirements[0];
59
- const uids = Array.isArray(name)
55
+ // Filter the preferred security schemes to only include the ones that are in the security requirements
56
+ const preferredSecurityNames = [
57
+ authentication?.preferredSecurityScheme ?? [],
58
+ ]
59
+ .flat()
60
+ .filter((name) => {
61
+ // Match up complex security requirements, array to array
62
+ if (Array.isArray(name)) {
63
+ // We match every element in the array
64
+ return securityRequirements.some((r) => Array.isArray(r) &&
65
+ r.length === name.length &&
66
+ r.every((v, i) => v === name[i]));
67
+ }
68
+ else
69
+ return securityRequirements.includes(name);
70
+ });
71
+ // Set the first security requirement if no preferred security schemes are set
72
+ if (!preferredSecurityNames.length && securityRequirements[0]) {
73
+ preferredSecurityNames.push(securityRequirements[0]);
74
+ }
75
+ // Map names to uids
76
+ const uids = preferredSecurityNames.map((name) => Array.isArray(name)
60
77
  ? name.map((k) => securitySchemeMap[k])
61
- : securitySchemeMap[name];
62
- return [uids];
78
+ : securitySchemeMap[name]);
79
+ return uids;
63
80
  };
64
81
  /**
65
82
  * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
@@ -203,6 +220,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
203
220
  ...operationWithoutSecurity,
204
221
  method,
205
222
  path: pathString,
223
+ security: operationSecurity,
206
224
  selectedSecuritySchemeUids,
207
225
  // Merge path and operation level parameters
208
226
  parameters: [