@scalar/oas-utils 0.2.102 → 0.2.104

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 (43) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/entities/spec/index.d.ts +1 -0
  3. package/dist/entities/spec/index.d.ts.map +1 -1
  4. package/dist/entities/spec/index.js +2 -1
  5. package/dist/entities/spec/operation.d.ts +243 -0
  6. package/dist/entities/spec/operation.d.ts.map +1 -0
  7. package/dist/entities/spec/operation.js +9 -0
  8. package/dist/entities/spec/request-examples.d.ts +267 -55
  9. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  10. package/dist/entities/spec/request-examples.js +43 -12
  11. package/dist/entities/spec/requests.d.ts +0 -2
  12. package/dist/entities/spec/requests.d.ts.map +1 -1
  13. package/dist/entities/workspace/workspace.d.ts +19 -0
  14. package/dist/entities/workspace/workspace.d.ts.map +1 -1
  15. package/dist/entities/workspace/workspace.js +11 -0
  16. package/dist/helpers/ensure-protocol.d.ts +3 -0
  17. package/dist/helpers/ensure-protocol.d.ts.map +1 -0
  18. package/dist/helpers/ensure-protocol.js +11 -0
  19. package/dist/helpers/fetchWithProxyFallback.d.ts +1 -1
  20. package/dist/helpers/fetchWithProxyFallback.d.ts.map +1 -1
  21. package/dist/helpers/index.d.ts +2 -1
  22. package/dist/helpers/index.d.ts.map +1 -1
  23. package/dist/helpers/index.js +2 -1
  24. package/dist/helpers/merge-urls.d.ts +15 -0
  25. package/dist/helpers/merge-urls.d.ts.map +1 -0
  26. package/dist/helpers/merge-urls.js +79 -0
  27. package/dist/helpers/redirectToProxy.d.ts.map +1 -1
  28. package/dist/helpers/redirectToProxy.js +3 -2
  29. package/dist/helpers/regexHelpers.d.ts +4 -0
  30. package/dist/helpers/regexHelpers.d.ts.map +1 -1
  31. package/dist/helpers/regexHelpers.js +4 -0
  32. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  33. package/dist/migrations/v-2.5.0/migration.js +11 -0
  34. package/dist/spec-getters/getRequestBodyFromOperation.d.ts +4 -10
  35. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  36. package/dist/spec-getters/getRequestBodyFromOperation.js +29 -57
  37. package/dist/transforms/import-spec.d.ts +1 -3
  38. package/dist/transforms/import-spec.d.ts.map +1 -1
  39. package/dist/transforms/import-spec.js +49 -11
  40. package/package.json +5 -7
  41. package/dist/helpers/concatenateUrlAndPath.d.ts +0 -5
  42. package/dist/helpers/concatenateUrlAndPath.d.ts.map +0 -1
  43. package/dist/helpers/concatenateUrlAndPath.js +0 -17
@@ -1 +1 @@
1
- {"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAezC,CAAA;AAUF,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,8BAA8B,CACtC,CAAA;AAED,eAAO,MAAM,sBAAsB;;;;;;;;;GAKtB,CAAA;AAEb;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAErE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS/B,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAKvE;;;;GAIG;A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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEvC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAOjE,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB;IAC/B,qCAAqC;;;;QA7CrC;;;;WAIG;;QAEH,0EAA0E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgD1E,CAAA;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 };
@@ -586,6 +586,4 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
586
586
  }>;
587
587
  export type Request = z.infer<typeof requestSchema>;
588
588
  export type RequestPayload = z.input<typeof requestSchema>;
589
- export type Operation = Request;
590
- export type OperationPayload = RequestPayload;
591
589
  //# sourceMappingURL=requests.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,oBAAoB,CAAA;AAI9E,eAAO,MAAM,cAAc,2FAUjB,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3D,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG;IACzD,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,wBAAwB;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,0BAA0B;IAC1B,MAAM,EAAE,aAAa,CAAA;IACrB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,cAAc,CAAA;IACvB,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAMD,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB;IAC3B;;;;;OAKG;;IAEH,kDAAkD;;IAElD,mHAAmH;;IAEnH;;;;OAIG;;IAEH;;;;;;OAMG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;IAEvB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG2B,CAAA;AA0BnD,8CAA8C;AAC9C,eAAO,MAAM,aAAa;IA3ExB;;;;;OAKG;;IAEH,kDAAkD;;IAElD,mHAAmH;;IAEnH;;;;OAIG;;IAEH;;;;;;OAMG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;OAEG;;;;;;;;;;;;IAGH,uBAAuB;;IAEvB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEvB,sBAAsB;;;;;;IAetB,eAAe;;IAEf,qBAAqB;;IAErB,kDAAkD;;IAElD,oCAAoC;;IAEpC,uDAAuD;;IAEvD,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOlC,CAAA;AAE/B,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA"}
@@ -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 };
@@ -0,0 +1,3 @@
1
+ /** Ensure URL has a protocol prefix */
2
+ export declare function ensureProtocol(url: string): string;
3
+ //# sourceMappingURL=ensure-protocol.d.ts.map
@@ -0,0 +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,CAKlD"}
@@ -0,0 +1,11 @@
1
+ import { REGEX } from './regexHelpers.js';
2
+
3
+ /** Ensure URL has a protocol prefix */
4
+ function ensureProtocol(url) {
5
+ if (REGEX.PROTOCOL.test(url))
6
+ return url;
7
+ // Default to http if no protocol is specified
8
+ return `http://${url.replace(/^\//, '')}`;
9
+ }
10
+
11
+ export { ensureProtocol };
@@ -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"}
@@ -1,6 +1,7 @@
1
1
  export { isDefined } from './is-defined.js';
2
2
  export { shouldIgnoreEntity } from './shouldIgnoreEntity.js';
3
- export * from './concatenateUrlAndPath.js';
3
+ export { combineUrlAndPath, mergeSearchParams, mergeUrls } from './merge-urls.js';
4
+ export { ensureProtocol } from './ensure-protocol.js';
4
5
  export * from './createHash.js';
5
6
  export * from './fetchSpecFromUrl.js';
6
7
  export * from './fetchWithProxyFallback.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
@@ -1,6 +1,7 @@
1
1
  export { isDefined } from './is-defined.js';
2
2
  export { shouldIgnoreEntity } from './shouldIgnoreEntity.js';
3
- export { concatenateUrlAndPath } from './concatenateUrlAndPath.js';
3
+ export { combineUrlAndPath, mergeSearchParams, mergeUrls } from './merge-urls.js';
4
+ export { ensureProtocol } from './ensure-protocol.js';
4
5
  export { createHash } from './createHash.js';
5
6
  export { fetchSpecFromUrl } from './fetchSpecFromUrl.js';
6
7
  export { fetchWithProxyFallback } from './fetchWithProxyFallback.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Merges multiple URLSearchParams objects, preserving multiple values per param
3
+ * within each source, but later sources overwrite earlier ones completely
4
+ * This should de-dupe our query params while allowing multiple keys for "arrays"
5
+ */
6
+ export declare const mergeSearchParams: (...params: URLSearchParams[]) => URLSearchParams;
7
+ /** Combines a base URL and a path ensuring there's only one slash between them */
8
+ export declare const combineUrlAndPath: (url: string, path: string) => string;
9
+ /**
10
+ * Creates a URL from the path and server
11
+ * also optionally merges query params if you include urlSearchParams
12
+ * This was re-written without using URL to support variables in the scheme
13
+ */
14
+ export declare const mergeUrls: (url: string, path: string, urlParams?: URLSearchParams, disableOriginPrefix?: boolean) => string;
15
+ //# sourceMappingURL=merge-urls.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,79 @@
1
+ import { REGEX } from './regexHelpers.js';
2
+ import { ensureProtocol } from './ensure-protocol.js';
3
+ import { isRelativePath } from './redirectToProxy.js';
4
+
5
+ /**
6
+ * Merges multiple URLSearchParams objects, preserving multiple values per param
7
+ * within each source, but later sources overwrite earlier ones completely
8
+ * This should de-dupe our query params while allowing multiple keys for "arrays"
9
+ */
10
+ const mergeSearchParams = (...params) => {
11
+ // We keep a merged record to ensure the next group will overwrite the previous
12
+ const merged = {};
13
+ // Loops over each group and grabs unique keys
14
+ params.forEach((p) => {
15
+ const keys = Array.from(p.keys());
16
+ const uniqueKeys = new Set(keys);
17
+ uniqueKeys.forEach((key) => {
18
+ const values = p.getAll(key);
19
+ const value = values.length > 1 ? values : (values[0] ?? '');
20
+ merged[key] = value;
21
+ });
22
+ });
23
+ const result = new URLSearchParams();
24
+ // We maintain multiple values for each key if they existed
25
+ Object.entries(merged).forEach(([key, value]) => {
26
+ if (Array.isArray(value)) {
27
+ value.forEach((v) => result.append(key, v));
28
+ }
29
+ else {
30
+ result.append(key, value);
31
+ }
32
+ });
33
+ return result;
34
+ };
35
+ /** Combines a base URL and a path ensuring there's only one slash between them */
36
+ const combineUrlAndPath = (url, path) => {
37
+ if (!path || url === path)
38
+ return url.trim();
39
+ if (!url)
40
+ return path.trim();
41
+ return `${url.trim()}/${path.trim()}`.replace(REGEX.MULTIPLE_SLASHES, '/');
42
+ };
43
+ /**
44
+ * Creates a URL from the path and server
45
+ * also optionally merges query params if you include urlSearchParams
46
+ * This was re-written without using URL to support variables in the scheme
47
+ */
48
+ const mergeUrls = (url, path, urlParams = new URLSearchParams(),
49
+ /** To disable prefixing the url with the origin or a scheme*/
50
+ disableOriginPrefix = false) => {
51
+ // Extract and merge all query params
52
+ if (url && (!isRelativePath(url) || typeof window !== 'undefined')) {
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);
59
+ // Extract search params from base URL if any
60
+ const [baseUrl = '', baseQuery] = base.split('?');
61
+ const baseParams = new URLSearchParams(baseQuery || '');
62
+ // Extract search params from path if any
63
+ const [pathWithoutQuery = '', pathQuery] = path.split('?');
64
+ const pathParams = new URLSearchParams(pathQuery || '');
65
+ // Merge the baseUrl and path
66
+ const mergedUrl = url === path ? baseUrl : combineUrlAndPath(baseUrl, pathWithoutQuery);
67
+ // Merge all search params
68
+ const mergedSearchParams = mergeSearchParams(baseParams, pathParams, urlParams);
69
+ // Build the final URL
70
+ const search = mergedSearchParams.toString();
71
+ return search ? `${mergedUrl}?${search}` : mergedUrl;
72
+ }
73
+ else if (path) {
74
+ return combineUrlAndPath(url, path);
75
+ }
76
+ return '';
77
+ };
78
+
79
+ export { combineUrlAndPath, mergeSearchParams, mergeUrls };
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAEA,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"}
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"}
@@ -1,3 +1,4 @@
1
+ import { REGEX } from './regexHelpers.js';
1
2
  import { isLocalUrl } from './isLocalUrl.js';
2
3
 
3
4
  /** Redirects the request to a proxy server with a given URL. */
@@ -15,8 +16,8 @@ function redirectToProxy(proxy, url) {
15
16
  }
16
17
  /** Check if the URL is relative or if it's a domain without protocol */
17
18
  const isRelativePath = (url) => {
18
- // Absolute URLs start with http:// or https://
19
- if (url.startsWith('http://') || url.startsWith('https://')) {
19
+ // Allow http:// https:// and other protocols such as file://
20
+ if (REGEX.PROTOCOL.test(url)) {
20
21
  return false;
21
22
  }
22
23
  // Check if it looks like a domain (contains dots and no spaces)
@@ -1,4 +1,8 @@
1
1
  export declare const REGEX: {
2
+ /** Checks for a valid scheme */
3
+ readonly PROTOCOL: RegExp;
4
+ /** Finds multiple slashes after the scheme to replace with a single slash */
5
+ readonly MULTIPLE_SLASHES: RegExp;
2
6
  readonly VARIABLES: RegExp;
3
7
  readonly PATH: RegExp;
4
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;;;;CAIR,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,4 +1,8 @@
1
1
  const REGEX = {
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,
2
6
  VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,
3
7
  PATH: /(?:{)([^{}]+)}(?!})/g,
4
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;