docusaurus-theme-openapi-docs 4.5.0 → 4.6.0

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 (119) hide show
  1. package/lib/markdown/schema.js +9 -1
  2. package/lib/theme/ApiExplorer/Accept/slice.d.ts +5 -2
  3. package/lib/theme/ApiExplorer/Authorization/index.js +50 -9
  4. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +145 -3
  5. package/lib/theme/ApiExplorer/Authorization/slice.js +3 -1
  6. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.d.ts +7 -0
  7. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +126 -0
  8. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +9 -0
  9. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +110 -0
  10. package/lib/theme/ApiExplorer/Body/index.js +94 -100
  11. package/lib/theme/ApiExplorer/Body/slice.d.ts +1056 -11
  12. package/lib/theme/ApiExplorer/Body/slice.js +22 -2
  13. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -1
  14. package/lib/theme/ApiExplorer/CodeSnippets/index.js +37 -26
  15. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  16. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +3 -3
  17. package/lib/theme/ApiExplorer/CodeTabs/index.js +2 -2
  18. package/lib/theme/ApiExplorer/ContentType/slice.d.ts +5 -2
  19. package/lib/theme/ApiExplorer/FormFileUpload/index.js +6 -1
  20. package/lib/theme/ApiExplorer/FormItem/index.js +6 -1
  21. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +2 -0
  22. package/lib/theme/ApiExplorer/FormTextInput/index.js +8 -1
  23. package/lib/theme/ApiExplorer/LiveEditor/index.js +11 -4
  24. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +15 -5
  25. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +11 -3
  26. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +12 -4
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +11 -2
  28. package/lib/theme/ApiExplorer/ParamOptions/index.js +11 -1
  29. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +0 -4
  30. package/lib/theme/ApiExplorer/ParamOptions/slice.js +4 -4
  31. package/lib/theme/ApiExplorer/Request/index.js +110 -17
  32. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +7 -1
  33. package/lib/theme/ApiExplorer/Request/makeRequest.js +94 -24
  34. package/lib/theme/ApiExplorer/Response/index.js +34 -14
  35. package/lib/theme/ApiExplorer/Response/slice.d.ts +31 -7
  36. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +208 -69
  37. package/lib/theme/ApiExplorer/Server/index.js +16 -2
  38. package/lib/theme/ApiExplorer/Server/slice.d.ts +49 -3
  39. package/lib/theme/ApiExplorer/buildPostmanRequest.js +46 -57
  40. package/lib/theme/ApiExplorer/index.js +11 -1
  41. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +19 -0
  42. package/lib/theme/ApiExplorer/{persistanceMiddleware.js → persistenceMiddleware.js} +16 -9
  43. package/lib/theme/ApiExplorer/storage-utils.d.ts +2 -2
  44. package/lib/theme/ApiExplorer/storage-utils.js +3 -3
  45. package/lib/theme/ApiItem/Layout/index.d.ts +1 -1
  46. package/lib/theme/ApiItem/hooks.d.ts +9 -9
  47. package/lib/theme/ApiItem/index.js +12 -8
  48. package/lib/theme/ApiItem/store.d.ts +55 -43
  49. package/lib/theme/ApiTabs/index.js +6 -1
  50. package/lib/theme/Example/_Example.scss +11 -0
  51. package/lib/theme/Example/index.d.ts +24 -0
  52. package/lib/theme/Example/index.js +170 -0
  53. package/lib/theme/ParamsDetails/index.js +9 -1
  54. package/lib/theme/ParamsItem/index.d.ts +1 -1
  55. package/lib/theme/ParamsItem/index.js +43 -74
  56. package/lib/theme/RequestSchema/index.js +18 -4
  57. package/lib/theme/ResponseExamples/index.js +23 -3
  58. package/lib/theme/ResponseSchema/index.js +97 -82
  59. package/lib/theme/Schema/index.js +106 -23
  60. package/lib/theme/SchemaItem/index.js +64 -36
  61. package/lib/theme/SchemaTabs/index.js +4 -1
  62. package/lib/theme/StatusCodes/index.js +11 -2
  63. package/lib/theme/styles.scss +5 -0
  64. package/lib/theme/translationIds.d.ts +90 -0
  65. package/lib/theme/translationIds.js +114 -0
  66. package/lib/types.d.ts +9 -1
  67. package/package.json +28 -28
  68. package/src/markdown/schema.ts +11 -1
  69. package/src/theme/ApiExplorer/Authorization/index.tsx +51 -10
  70. package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
  71. package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
  72. package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
  73. package/src/theme/ApiExplorer/Body/index.tsx +87 -107
  74. package/src/theme/ApiExplorer/Body/json2xml.d.ts +8 -0
  75. package/src/theme/ApiExplorer/Body/slice.ts +40 -1
  76. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +43 -29
  77. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  78. package/src/theme/ApiExplorer/CodeTabs/index.tsx +6 -5
  79. package/src/theme/ApiExplorer/ContentType/index.tsx +1 -1
  80. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +6 -1
  81. package/src/theme/ApiExplorer/FormItem/index.tsx +8 -1
  82. package/src/theme/ApiExplorer/FormTextInput/index.tsx +10 -1
  83. package/src/theme/ApiExplorer/LiveEditor/index.tsx +11 -4
  84. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +16 -6
  85. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +12 -4
  86. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +12 -4
  87. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +12 -3
  88. package/src/theme/ApiExplorer/ParamOptions/index.tsx +10 -2
  89. package/src/theme/ApiExplorer/ParamOptions/slice.ts +1 -1
  90. package/src/theme/ApiExplorer/Request/index.tsx +108 -17
  91. package/src/theme/ApiExplorer/Request/makeRequest.ts +106 -25
  92. package/src/theme/ApiExplorer/Response/index.tsx +30 -8
  93. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +157 -69
  94. package/src/theme/ApiExplorer/Server/index.tsx +12 -4
  95. package/src/theme/ApiExplorer/buildPostmanRequest.ts +47 -63
  96. package/src/theme/ApiExplorer/index.tsx +10 -1
  97. package/src/theme/ApiExplorer/{persistanceMiddleware.ts → persistenceMiddleware.ts} +23 -13
  98. package/src/theme/ApiExplorer/storage-utils.ts +4 -4
  99. package/src/theme/ApiItem/Layout/index.tsx +1 -1
  100. package/src/theme/ApiItem/index.tsx +12 -7
  101. package/src/theme/ApiTabs/index.tsx +6 -1
  102. package/src/theme/Example/_Example.scss +11 -0
  103. package/src/theme/Example/index.tsx +168 -0
  104. package/src/theme/Markdown/index.d.ts +8 -0
  105. package/src/theme/ParamsDetails/index.tsx +10 -1
  106. package/src/theme/ParamsItem/index.tsx +38 -54
  107. package/src/theme/RequestSchema/index.tsx +19 -4
  108. package/src/theme/ResponseExamples/index.tsx +23 -3
  109. package/src/theme/ResponseSchema/index.tsx +73 -61
  110. package/src/theme/Schema/index.tsx +128 -33
  111. package/src/theme/SchemaItem/index.tsx +51 -33
  112. package/src/theme/SchemaTabs/index.tsx +4 -1
  113. package/src/theme/StatusCodes/index.tsx +13 -2
  114. package/src/theme/styles.scss +5 -0
  115. package/src/theme/translationIds.ts +111 -0
  116. package/src/theme-openapi.d.ts +7 -275
  117. package/src/types.ts +9 -1
  118. package/tsconfig.tsbuildinfo +1 -1
  119. package/lib/theme/ApiExplorer/persistanceMiddleware.d.ts +0 -3
@@ -70,6 +70,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
70
70
  // @ts-nocheck
71
71
  const react_1 = __importStar(require("react"));
72
72
  const client_1 = require("@docusaurus/plugin-content-docs/client");
73
+ const Translate_1 = require("@docusaurus/Translate");
74
+ const useDocusaurusContext_1 = __importDefault(
75
+ require("@docusaurus/useDocusaurusContext")
76
+ );
73
77
  const Accept_1 = __importDefault(require("@theme/ApiExplorer/Accept"));
74
78
  const Authorization_1 = __importDefault(
75
79
  require("@theme/ApiExplorer/Authorization")
@@ -87,13 +91,20 @@ const ParamOptions_1 = __importDefault(
87
91
  const slice_1 = require("@theme/ApiExplorer/Response/slice");
88
92
  const Server_1 = __importDefault(require("@theme/ApiExplorer/Server"));
89
93
  const hooks_1 = require("@theme/ApiItem/hooks");
94
+ const translationIds_1 = require("@theme/translationIds");
90
95
  const sdk = __importStar(require("postman-collection"));
91
96
  const react_hook_form_1 = require("react-hook-form");
92
- const makeRequest_1 = __importDefault(require("./makeRequest"));
97
+ const makeRequest_1 = __importStar(require("./makeRequest"));
93
98
  function Request({ item }) {
94
99
  const postman = new sdk.Request(item.postman);
95
100
  const metadata = (0, client_1.useDoc)();
96
- const { proxy, hide_send_button: hideSendButton } = metadata.frontMatter;
101
+ const { proxy: frontMatterProxy, hide_send_button: hideSendButton } =
102
+ metadata.frontMatter;
103
+ const { siteConfig } = (0, useDocusaurusContext_1.default)();
104
+ const themeConfig = siteConfig.themeConfig;
105
+ const requestTimeout = themeConfig.api?.requestTimeout;
106
+ // Frontmatter proxy (per-spec) takes precedence over theme config proxy (site-wide)
107
+ const proxy = frontMatterProxy ?? themeConfig.api?.proxy;
97
108
  const pathParams = (0, hooks_1.useTypedSelector)(
98
109
  (state) => state.params.path
99
110
  );
@@ -178,11 +189,52 @@ function Request({ item }) {
178
189
  res.headers &&
179
190
  dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
180
191
  };
192
+ const getErrorMessage = (errorType) => {
193
+ switch (errorType) {
194
+ case "timeout":
195
+ return (0, Translate_1.translate)({
196
+ id: translationIds_1.OPENAPI_REQUEST.ERROR_TIMEOUT,
197
+ message:
198
+ "The request timed out waiting for the server to respond. Please try again. If the issue persists, try using a different client (e.g., curl) with a longer timeout.",
199
+ });
200
+ case "network":
201
+ return (0, Translate_1.translate)({
202
+ id: translationIds_1.OPENAPI_REQUEST.ERROR_NETWORK,
203
+ message:
204
+ "Unable to reach the server. Please check your network connection and verify the server URL is correct. If the server is running, this may be a CORS issue.",
205
+ });
206
+ case "cors":
207
+ return (0, Translate_1.translate)({
208
+ id: translationIds_1.OPENAPI_REQUEST.ERROR_CORS,
209
+ message:
210
+ "The request was blocked, possibly due to CORS restrictions. Ensure the server allows requests from this origin, or try using a proxy.",
211
+ });
212
+ case "unknown":
213
+ default:
214
+ return (0, Translate_1.translate)({
215
+ id: translationIds_1.OPENAPI_REQUEST.ERROR_UNKNOWN,
216
+ message:
217
+ "An unexpected error occurred while making the request. Please try again.",
218
+ });
219
+ }
220
+ };
181
221
  const onSubmit = async (data) => {
182
- dispatch((0, slice_1.setResponse)("Fetching..."));
222
+ dispatch(
223
+ (0, slice_1.setResponse)(
224
+ (0, Translate_1.translate)({
225
+ id: translationIds_1.OPENAPI_REQUEST.FETCHING_MESSAGE,
226
+ message: "Fetching...",
227
+ })
228
+ )
229
+ );
183
230
  try {
184
231
  await delay(1200);
185
- const res = await (0, makeRequest_1.default)(postmanRequest, proxy, body);
232
+ const res = await (0, makeRequest_1.default)(
233
+ postmanRequest,
234
+ proxy,
235
+ body,
236
+ requestTimeout
237
+ );
186
238
  if (res.headers.get("content-type")?.includes("text/event-stream")) {
187
239
  await handleEventStream(res);
188
240
  } else {
@@ -190,7 +242,16 @@ function Request({ item }) {
190
242
  }
191
243
  } catch (e) {
192
244
  console.log(e);
193
- dispatch((0, slice_1.setResponse)("Connection failed"));
245
+ let errorMessage;
246
+ if (e instanceof makeRequest_1.RequestError) {
247
+ errorMessage = getErrorMessage(e.type);
248
+ } else {
249
+ errorMessage = (0, Translate_1.translate)({
250
+ id: translationIds_1.OPENAPI_REQUEST.CONNECTION_FAILED,
251
+ message: "Connection failed",
252
+ });
253
+ }
254
+ dispatch((0, slice_1.setResponse)(errorMessage));
194
255
  dispatch((0, slice_1.clearCode)());
195
256
  dispatch((0, slice_1.clearHeaders)());
196
257
  }
@@ -198,7 +259,7 @@ function Request({ item }) {
198
259
  const showServerOptions = serverOptions.length > 0;
199
260
  const showAcceptOptions = acceptOptions.length > 1;
200
261
  const showRequestBody = contentType !== undefined;
201
- const showRequestButton = item.servers && !hideSendButton;
262
+ const showRequestButton = (item.servers || proxy) && !hideSendButton;
202
263
  const showAuth = authSelected !== undefined;
203
264
  const showParams = allParams.length > 0;
204
265
  const requestBodyRequired = item.requestBody?.required;
@@ -207,7 +268,8 @@ function Request({ item }) {
207
268
  !showAuth &&
208
269
  !showParams &&
209
270
  !showRequestBody &&
210
- !showServerOptions
271
+ !showServerOptions &&
272
+ !showRequestButton
211
273
  ) {
212
274
  return null;
213
275
  }
@@ -242,7 +304,10 @@ function Request({ item }) {
242
304
  react_1.default.createElement(
243
305
  "span",
244
306
  { className: "openapi-explorer__request-title" },
245
- "Request "
307
+ (0, Translate_1.translate)({
308
+ id: translationIds_1.OPENAPI_REQUEST.REQUEST_TITLE,
309
+ message: "Request",
310
+ })
246
311
  ),
247
312
  allDetailsExpanded
248
313
  ? react_1.default.createElement(
@@ -251,7 +316,10 @@ function Request({ item }) {
251
316
  className: "openapi-explorer__expand-details-btn",
252
317
  onClick: collapseAllDetails,
253
318
  },
254
- "Collapse all"
319
+ (0, Translate_1.translate)({
320
+ id: translationIds_1.OPENAPI_REQUEST.COLLAPSE_ALL,
321
+ message: "Collapse all",
322
+ })
255
323
  )
256
324
  : react_1.default.createElement(
257
325
  "span",
@@ -259,7 +327,10 @@ function Request({ item }) {
259
327
  className: "openapi-explorer__expand-details-btn",
260
328
  onClick: expandAllDetails,
261
329
  },
262
- "Expand all"
330
+ (0, Translate_1.translate)({
331
+ id: translationIds_1.OPENAPI_REQUEST.EXPAND_ALL,
332
+ message: "Expand all",
333
+ })
263
334
  )
264
335
  ),
265
336
  react_1.default.createElement(
@@ -282,7 +353,10 @@ function Request({ item }) {
282
353
  setExpandServer(!expandServer);
283
354
  },
284
355
  },
285
- "Base URL"
356
+ (0, Translate_1.translate)({
357
+ id: translationIds_1.OPENAPI_REQUEST.BASE_URL_TITLE,
358
+ message: "Base URL",
359
+ })
286
360
  ),
287
361
  react_1.default.createElement(Server_1.default, null)
288
362
  ),
@@ -302,7 +376,10 @@ function Request({ item }) {
302
376
  setExpandAuth(!expandAuth);
303
377
  },
304
378
  },
305
- "Auth"
379
+ (0, Translate_1.translate)({
380
+ id: translationIds_1.OPENAPI_REQUEST.AUTH_TITLE,
381
+ message: "Auth",
382
+ })
306
383
  ),
307
384
  react_1.default.createElement(Authorization_1.default, null)
308
385
  ),
@@ -323,7 +400,10 @@ function Request({ item }) {
323
400
  setExpandParams(!expandParams);
324
401
  },
325
402
  },
326
- "Parameters"
403
+ (0, Translate_1.translate)({
404
+ id: translationIds_1.OPENAPI_REQUEST.PARAMETERS_TITLE,
405
+ message: "Parameters",
406
+ })
327
407
  ),
328
408
  react_1.default.createElement(ParamOptions_1.default, null)
329
409
  ),
@@ -343,12 +423,19 @@ function Request({ item }) {
343
423
  setExpandBody(!expandBody);
344
424
  },
345
425
  },
346
- "Body",
426
+ (0, Translate_1.translate)({
427
+ id: translationIds_1.OPENAPI_REQUEST.BODY_TITLE,
428
+ message: "Body",
429
+ }),
347
430
  requestBodyRequired &&
348
431
  react_1.default.createElement(
349
432
  "span",
350
433
  { className: "openapi-schema__required" },
351
- "\u00A0required"
434
+ "\u00A0",
435
+ (0, Translate_1.translate)({
436
+ id: translationIds_1.OPENAPI_REQUEST.REQUIRED_LABEL,
437
+ message: "required",
438
+ })
352
439
  )
353
440
  ),
354
441
  react_1.default.createElement(
@@ -378,7 +465,10 @@ function Request({ item }) {
378
465
  setExpandAccept(!expandAccept);
379
466
  },
380
467
  },
381
- "Accept"
468
+ (0, Translate_1.translate)({
469
+ id: translationIds_1.OPENAPI_REQUEST.ACCEPT_TITLE,
470
+ message: "Accept",
471
+ })
382
472
  ),
383
473
  react_1.default.createElement(Accept_1.default, null)
384
474
  ),
@@ -387,7 +477,10 @@ function Request({ item }) {
387
477
  react_1.default.createElement(
388
478
  "button",
389
479
  { className: "openapi-explorer__request-btn", type: "submit" },
390
- "Send API Request"
480
+ (0, Translate_1.translate)({
481
+ id: translationIds_1.OPENAPI_REQUEST.SEND_BUTTON,
482
+ message: "Send API Request",
483
+ })
391
484
  )
392
485
  )
393
486
  )
@@ -1,4 +1,10 @@
1
1
  import { Body } from "@theme/ApiExplorer/Body/slice";
2
2
  import * as sdk from "postman-collection";
3
- declare function makeRequest(request: sdk.Request, proxy: string | undefined, _body: Body): Promise<any>;
3
+ export type RequestErrorType = "timeout" | "network" | "cors" | "abort" | "unknown";
4
+ export declare class RequestError extends Error {
5
+ type: RequestErrorType;
6
+ originalError?: Error;
7
+ constructor(type: RequestErrorType, message: string, originalError?: Error);
8
+ }
9
+ declare function makeRequest(request: sdk.Request, proxy: string | undefined, _body: Body, timeout?: number): Promise<Response>;
4
10
  export default makeRequest;
@@ -6,13 +6,65 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- function fetchWithtimeout(url, options, timeout = 5000) {
10
- return Promise.race([
11
- fetch(url, options),
12
- new Promise((_, reject) =>
13
- setTimeout(() => reject(new Error("Request timed out")), timeout)
14
- ),
15
- ]);
9
+ exports.RequestError = void 0;
10
+ class RequestError extends Error {
11
+ type;
12
+ originalError;
13
+ constructor(type, message, originalError) {
14
+ super(message);
15
+ this.name = "RequestError";
16
+ this.type = type;
17
+ this.originalError = originalError;
18
+ }
19
+ }
20
+ exports.RequestError = RequestError;
21
+ const DEFAULT_REQUEST_TIMEOUT = 30000; // 30 seconds
22
+ function fetchWithtimeout(url, options, timeout = DEFAULT_REQUEST_TIMEOUT) {
23
+ const controller = new AbortController();
24
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
25
+ return fetch(url, {
26
+ ...options,
27
+ signal: controller.signal,
28
+ })
29
+ .then((response) => {
30
+ clearTimeout(timeoutId);
31
+ return response;
32
+ })
33
+ .catch((error) => {
34
+ clearTimeout(timeoutId);
35
+ // Check if it was an abort due to timeout
36
+ if (error.name === "AbortError") {
37
+ throw new RequestError(
38
+ "timeout",
39
+ "The request timed out waiting for the server to respond. Please try again. If the issue persists, try using a different client (e.g., curl) with a longer timeout.",
40
+ error
41
+ );
42
+ }
43
+ // Check for network errors (offline, DNS failure, etc.)
44
+ if (error instanceof TypeError && error.message === "Failed to fetch") {
45
+ // This could be CORS, network failure, or the server being unreachable
46
+ throw new RequestError(
47
+ "network",
48
+ "Unable to reach the server. Please check your network connection and verify the server URL is correct. If the server is running, this may be a CORS issue.",
49
+ error
50
+ );
51
+ }
52
+ // Handle other TypeErrors that might indicate CORS issues
53
+ if (error instanceof TypeError) {
54
+ throw new RequestError(
55
+ "cors",
56
+ "The request was blocked, possibly due to CORS restrictions. Ensure the server allows requests from this origin, or try using a proxy.",
57
+ error
58
+ );
59
+ }
60
+ // Generic error fallback
61
+ throw new RequestError(
62
+ "unknown",
63
+ error.message ||
64
+ "An unexpected error occurred while making the request.",
65
+ error
66
+ );
67
+ });
16
68
  }
17
69
  async function loadImage(content) {
18
70
  return new Promise((accept, reject) => {
@@ -33,7 +85,12 @@ async function loadImage(content) {
33
85
  reader.readAsArrayBuffer(content);
34
86
  });
35
87
  }
36
- async function makeRequest(request, proxy, _body) {
88
+ async function makeRequest(
89
+ request,
90
+ proxy,
91
+ _body,
92
+ timeout = DEFAULT_REQUEST_TIMEOUT
93
+ ) {
37
94
  const headers = request.toJSON().header;
38
95
  let myHeaders = new Headers();
39
96
  if (headers) {
@@ -171,7 +228,8 @@ async function makeRequest(request, proxy, _body) {
171
228
  let normalizedProxy = proxy.replace(/\/$/, "") + "/";
172
229
  finalUrl = normalizedProxy + request.url.toString();
173
230
  }
174
- return fetchWithtimeout(finalUrl, requestOptions).then((response) => {
231
+ try {
232
+ const response = await fetchWithtimeout(finalUrl, requestOptions, timeout);
175
233
  const contentType = response.headers.get("content-type");
176
234
  let fileExtension = "";
177
235
  if (contentType) {
@@ -199,25 +257,37 @@ async function makeRequest(request, proxy, _body) {
199
257
  fileExtension = ".zip";
200
258
  }
201
259
  if (fileExtension) {
202
- return response.blob().then((blob) => {
203
- const url = window.URL.createObjectURL(blob);
204
- const link = document.createElement("a");
205
- link.href = url;
206
- // Now the file name includes the extension
207
- link.setAttribute("download", `file${fileExtension}`);
208
- // These two lines are necessary to make the link click in Firefox
209
- link.style.display = "none";
210
- document.body.appendChild(link);
211
- link.click();
212
- // After link is clicked, it's safe to remove it.
213
- setTimeout(() => document.body.removeChild(link), 0);
214
- return response;
215
- });
260
+ const blob = await response.blob();
261
+ const url = window.URL.createObjectURL(blob);
262
+ const link = document.createElement("a");
263
+ link.href = url;
264
+ // Now the file name includes the extension
265
+ link.setAttribute("download", `file${fileExtension}`);
266
+ // These two lines are necessary to make the link click in Firefox
267
+ link.style.display = "none";
268
+ document.body.appendChild(link);
269
+ link.click();
270
+ // After link is clicked, it's safe to remove it.
271
+ setTimeout(() => document.body.removeChild(link), 0);
272
+ return response;
216
273
  } else {
217
274
  return response;
218
275
  }
219
276
  }
220
277
  return response;
221
- });
278
+ } catch (error) {
279
+ // Re-throw RequestError instances as-is
280
+ if (error instanceof RequestError) {
281
+ throw error;
282
+ }
283
+ // Wrap unexpected errors
284
+ throw new RequestError(
285
+ "unknown",
286
+ error instanceof Error
287
+ ? error.message
288
+ : "An unexpected error occurred while processing the response.",
289
+ error instanceof Error ? error : undefined
290
+ );
291
+ }
222
292
  }
223
293
  exports.default = makeRequest;
@@ -14,12 +14,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const react_1 = __importDefault(require("react"));
15
15
  const client_1 = require("@docusaurus/plugin-content-docs/client");
16
16
  const theme_common_1 = require("@docusaurus/theme-common");
17
+ const Translate_1 = require("@docusaurus/Translate");
18
+ const useDocusaurusContext_1 = __importDefault(
19
+ require("@docusaurus/useDocusaurusContext")
20
+ );
17
21
  const ApiCodeBlock_1 = __importDefault(
18
22
  require("@theme/ApiExplorer/ApiCodeBlock")
19
23
  );
20
24
  const hooks_1 = require("@theme/ApiItem/hooks");
21
25
  const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
22
26
  const TabItem_1 = __importDefault(require("@theme/TabItem"));
27
+ const translationIds_1 = require("@theme/translationIds");
23
28
  const clsx_1 = __importDefault(require("clsx"));
24
29
  const slice_1 = require("./slice");
25
30
  // TODO: We probably shouldn't attempt to format XML...
@@ -42,7 +47,10 @@ function formatXml(xml) {
42
47
  }
43
48
  function Response({ item }) {
44
49
  const metadata = (0, client_1.useDoc)();
50
+ const { siteConfig } = (0, useDocusaurusContext_1.default)();
51
+ const themeConfig = siteConfig.themeConfig;
45
52
  const hideSendButton = metadata.frontMatter.hide_send_button;
53
+ const proxy = metadata.frontMatter.proxy ?? themeConfig.api?.proxy;
46
54
  const prismTheme = (0, theme_common_1.usePrismTheme)();
47
55
  const code = (0, hooks_1.useTypedSelector)((state) => state.response.code);
48
56
  const headers = (0, hooks_1.useTypedSelector)(
@@ -60,7 +68,7 @@ function Response({ item }) {
60
68
  : parseInt(code) >= 200 && parseInt(code) < 300
61
69
  ? "openapi-response__dot--success"
62
70
  : "openapi-response__dot--info");
63
- if (!item.servers || hideSendButton) {
71
+ if ((!item.servers && !proxy) || hideSendButton) {
64
72
  return null;
65
73
  }
66
74
  let prettyResponse = response;
@@ -82,7 +90,10 @@ function Response({ item }) {
82
90
  react_1.default.createElement(
83
91
  "span",
84
92
  { className: "openapi-explorer__response-title" },
85
- "Response"
93
+ (0, Translate_1.translate)({
94
+ id: translationIds_1.OPENAPI_RESPONSE.TITLE,
95
+ message: "Response",
96
+ })
86
97
  ),
87
98
  react_1.default.createElement(
88
99
  "span",
@@ -94,7 +105,10 @@ function Response({ item }) {
94
105
  dispatch((0, slice_1.clearHeaders)());
95
106
  },
96
107
  },
97
- "Clear"
108
+ (0, Translate_1.translate)({
109
+ id: translationIds_1.OPENAPI_RESPONSE.CLEAR,
110
+ message: "Clear",
111
+ })
98
112
  )
99
113
  ),
100
114
  react_1.default.createElement(
@@ -143,19 +157,23 @@ function Response({ item }) {
143
157
  className:
144
158
  "openapi-explorer__response-placeholder-message",
145
159
  },
146
- "Click the ",
147
- react_1.default.createElement(
148
- "code",
149
- null,
150
- "Send API Request"
151
- ),
152
- " button above and see the response here!"
160
+ (0, Translate_1.translate)({
161
+ id: translationIds_1.OPENAPI_RESPONSE.PLACEHOLDER,
162
+ message:
163
+ "Click the <code>Send API Request</code> button above and see the response here!",
164
+ })
153
165
  )
154
166
  )
155
167
  ),
156
168
  react_1.default.createElement(
157
169
  TabItem_1.default,
158
- { label: "Headers", value: "headers" },
170
+ {
171
+ label: (0, Translate_1.translate)({
172
+ id: translationIds_1.OPENAPI_RESPONSE.HEADERS_TAB,
173
+ message: "Headers",
174
+ }),
175
+ value: "headers",
176
+ },
159
177
  react_1.default.createElement(
160
178
  ApiCodeBlock_1.default,
161
179
  {
@@ -183,9 +201,11 @@ function Response({ item }) {
183
201
  : react_1.default.createElement(
184
202
  "p",
185
203
  { className: "openapi-explorer__response-placeholder-message" },
186
- "Click the ",
187
- react_1.default.createElement("code", null, "Send API Request"),
188
- " button above and see the response here!"
204
+ (0, Translate_1.translate)({
205
+ id: translationIds_1.OPENAPI_RESPONSE.PLACEHOLDER,
206
+ message:
207
+ "Click the <code>Send API Request</code> button above and see the response here!",
208
+ })
189
209
  )
190
210
  )
191
211
  );
@@ -5,13 +5,37 @@ export interface State {
5
5
  headers?: string;
6
6
  }
7
7
  export declare const slice: import("@reduxjs/toolkit").Slice<State, {
8
- setResponse: (state: import("immer/dist/internal").WritableDraft<State>, action: PayloadAction<string>) => void;
9
- setCode: (state: import("immer/dist/internal").WritableDraft<State>, action: PayloadAction<string>) => void;
10
- setHeaders: (state: import("immer/dist/internal").WritableDraft<State>, action: PayloadAction<string>) => void;
11
- clearResponse: (state: import("immer/dist/internal").WritableDraft<State>) => void;
12
- clearCode: (state: import("immer/dist/internal").WritableDraft<State>) => void;
13
- clearHeaders: (state: import("immer/dist/internal").WritableDraft<State>) => void;
14
- }, "response">;
8
+ setResponse: (state: {
9
+ value?: string | undefined;
10
+ code?: string | undefined;
11
+ headers?: string | undefined;
12
+ }, action: PayloadAction<string>) => void;
13
+ setCode: (state: {
14
+ value?: string | undefined;
15
+ code?: string | undefined;
16
+ headers?: string | undefined;
17
+ }, action: PayloadAction<string>) => void;
18
+ setHeaders: (state: {
19
+ value?: string | undefined;
20
+ code?: string | undefined;
21
+ headers?: string | undefined;
22
+ }, action: PayloadAction<string>) => void;
23
+ clearResponse: (state: {
24
+ value?: string | undefined;
25
+ code?: string | undefined;
26
+ headers?: string | undefined;
27
+ }) => void;
28
+ clearCode: (state: {
29
+ value?: string | undefined;
30
+ code?: string | undefined;
31
+ headers?: string | undefined;
32
+ }) => void;
33
+ clearHeaders: (state: {
34
+ value?: string | undefined;
35
+ code?: string | undefined;
36
+ headers?: string | undefined;
37
+ }) => void;
38
+ }, "response", "response", import("@reduxjs/toolkit").SliceSelectors<State>>;
15
39
  export declare const setResponse: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "response/setResponse">, clearResponse: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"response/clearResponse">, setCode: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "response/setCode">, clearCode: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"response/clearCode">, setHeaders: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "response/setHeaders">, clearHeaders: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"response/clearHeaders">;
16
40
  declare const _default: import("redux").Reducer<State>;
17
41
  export default _default;