docusaurus-theme-openapi-docs 4.5.1 → 4.7.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 (133) hide show
  1. package/lib/markdown/schema.js +14 -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 +322 -193
  11. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.d.ts +13 -0
  12. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.js +133 -0
  13. package/lib/theme/ApiExplorer/Body/slice.d.ts +1056 -11
  14. package/lib/theme/ApiExplorer/Body/slice.js +22 -2
  15. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -1
  16. package/lib/theme/ApiExplorer/CodeSnippets/index.js +37 -26
  17. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  18. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +3 -3
  19. package/lib/theme/ApiExplorer/CodeTabs/index.js +2 -2
  20. package/lib/theme/ApiExplorer/ContentType/slice.d.ts +5 -2
  21. package/lib/theme/ApiExplorer/FormFileUpload/index.js +6 -1
  22. package/lib/theme/ApiExplorer/FormItem/index.js +6 -1
  23. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +2 -0
  24. package/lib/theme/ApiExplorer/FormTextInput/index.js +8 -1
  25. package/lib/theme/ApiExplorer/LiveEditor/index.js +11 -4
  26. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +15 -5
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +11 -3
  28. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +12 -4
  29. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +11 -2
  30. package/lib/theme/ApiExplorer/ParamOptions/index.js +11 -1
  31. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +0 -4
  32. package/lib/theme/ApiExplorer/ParamOptions/slice.js +4 -4
  33. package/lib/theme/ApiExplorer/Request/index.js +110 -17
  34. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +7 -1
  35. package/lib/theme/ApiExplorer/Request/makeRequest.js +94 -24
  36. package/lib/theme/ApiExplorer/Response/index.js +34 -14
  37. package/lib/theme/ApiExplorer/Response/slice.d.ts +31 -7
  38. package/lib/theme/ApiExplorer/SchemaSelection/index.d.ts +2 -0
  39. package/lib/theme/ApiExplorer/SchemaSelection/index.js +36 -0
  40. package/lib/theme/ApiExplorer/SchemaSelection/slice.d.ts +37 -0
  41. package/lib/theme/ApiExplorer/SchemaSelection/slice.js +39 -0
  42. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +208 -69
  43. package/lib/theme/ApiExplorer/Server/index.js +16 -2
  44. package/lib/theme/ApiExplorer/Server/slice.d.ts +49 -3
  45. package/lib/theme/ApiExplorer/buildPostmanRequest.js +46 -57
  46. package/lib/theme/ApiExplorer/index.js +4 -0
  47. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +21 -0
  48. package/lib/theme/ApiExplorer/{persistanceMiddleware.js → persistenceMiddleware.js} +16 -9
  49. package/lib/theme/ApiExplorer/storage-utils.d.ts +2 -2
  50. package/lib/theme/ApiExplorer/storage-utils.js +3 -3
  51. package/lib/theme/ApiItem/Layout/index.d.ts +1 -1
  52. package/lib/theme/ApiItem/hooks.d.ts +10 -9
  53. package/lib/theme/ApiItem/index.js +13 -8
  54. package/lib/theme/ApiItem/store.d.ts +61 -43
  55. package/lib/theme/ApiItem/store.js +6 -2
  56. package/lib/theme/ApiTabs/index.js +6 -1
  57. package/lib/theme/Example/_Example.scss +11 -0
  58. package/lib/theme/Example/index.d.ts +24 -0
  59. package/lib/theme/Example/index.js +170 -0
  60. package/lib/theme/ParamsDetails/index.js +9 -1
  61. package/lib/theme/ParamsItem/index.d.ts +1 -1
  62. package/lib/theme/ParamsItem/index.js +43 -74
  63. package/lib/theme/RequestSchema/index.js +68 -48
  64. package/lib/theme/ResponseExamples/index.js +23 -3
  65. package/lib/theme/ResponseSchema/index.js +97 -82
  66. package/lib/theme/Schema/index.d.ts +6 -0
  67. package/lib/theme/Schema/index.js +240 -31
  68. package/lib/theme/SchemaItem/index.js +64 -36
  69. package/lib/theme/SchemaTabs/index.d.ts +8 -1
  70. package/lib/theme/SchemaTabs/index.js +14 -2
  71. package/lib/theme/StatusCodes/index.d.ts +1 -1
  72. package/lib/theme/StatusCodes/index.js +11 -2
  73. package/lib/theme/styles.scss +15 -0
  74. package/lib/theme/translationIds.d.ts +90 -0
  75. package/lib/theme/translationIds.js +114 -0
  76. package/package.json +28 -28
  77. package/src/markdown/schema.ts +17 -1
  78. package/src/theme/ApiExplorer/Authorization/index.tsx +51 -10
  79. package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
  80. package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
  81. package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
  82. package/src/theme/ApiExplorer/Body/index.tsx +262 -198
  83. package/{lib/types.js → src/theme/ApiExplorer/Body/json2xml.d.ts} +2 -2
  84. package/src/theme/ApiExplorer/Body/resolveSchemaWithSelections.ts +155 -0
  85. package/src/theme/ApiExplorer/Body/slice.ts +40 -1
  86. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +43 -29
  87. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  88. package/src/theme/ApiExplorer/CodeTabs/index.tsx +6 -5
  89. package/src/theme/ApiExplorer/ContentType/index.tsx +1 -1
  90. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +6 -1
  91. package/src/theme/ApiExplorer/FormItem/index.tsx +8 -1
  92. package/src/theme/ApiExplorer/FormTextInput/index.tsx +10 -1
  93. package/src/theme/ApiExplorer/LiveEditor/index.tsx +11 -4
  94. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +16 -6
  95. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +12 -4
  96. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +12 -4
  97. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +12 -3
  98. package/src/theme/ApiExplorer/ParamOptions/index.tsx +10 -2
  99. package/src/theme/ApiExplorer/ParamOptions/slice.ts +1 -1
  100. package/src/theme/ApiExplorer/Request/index.tsx +108 -17
  101. package/src/theme/ApiExplorer/Request/makeRequest.ts +106 -25
  102. package/src/theme/ApiExplorer/Response/index.tsx +30 -8
  103. package/src/theme/ApiExplorer/SchemaSelection/index.ts +13 -0
  104. package/src/theme/ApiExplorer/SchemaSelection/slice.ts +46 -0
  105. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +157 -69
  106. package/src/theme/ApiExplorer/Server/index.tsx +12 -4
  107. package/src/theme/ApiExplorer/buildPostmanRequest.ts +47 -63
  108. package/src/theme/ApiExplorer/index.tsx +5 -0
  109. package/src/theme/ApiExplorer/{persistanceMiddleware.ts → persistenceMiddleware.ts} +23 -13
  110. package/src/theme/ApiExplorer/storage-utils.ts +4 -4
  111. package/src/theme/ApiItem/Layout/index.tsx +1 -1
  112. package/src/theme/ApiItem/index.tsx +13 -7
  113. package/src/theme/ApiItem/store.ts +2 -0
  114. package/src/theme/ApiTabs/index.tsx +6 -1
  115. package/src/theme/Example/_Example.scss +11 -0
  116. package/src/theme/Example/index.tsx +168 -0
  117. package/src/theme/Markdown/index.d.ts +8 -0
  118. package/src/theme/ParamsDetails/index.tsx +10 -1
  119. package/src/theme/ParamsItem/index.tsx +38 -54
  120. package/src/theme/RequestSchema/index.tsx +60 -35
  121. package/src/theme/ResponseExamples/index.tsx +23 -3
  122. package/src/theme/ResponseSchema/index.tsx +73 -61
  123. package/src/theme/Schema/index.tsx +307 -55
  124. package/src/theme/SchemaItem/index.tsx +51 -33
  125. package/src/theme/SchemaTabs/index.tsx +19 -5
  126. package/src/theme/StatusCodes/index.tsx +13 -3
  127. package/src/theme/styles.scss +15 -0
  128. package/src/theme/translationIds.ts +111 -0
  129. package/src/theme-openapi.d.ts +7 -275
  130. package/src/{types.ts → types.d.ts} +9 -1
  131. package/tsconfig.tsbuildinfo +1 -1
  132. package/lib/theme/ApiExplorer/persistanceMiddleware.d.ts +0 -3
  133. package/lib/types.d.ts +0 -46
@@ -7,6 +7,9 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
11
+ import { OPENAPI_SECURITY_SCHEMES } from "@theme/translationIds";
12
+
10
13
  import Link from "@docusaurus/Link";
11
14
  import { useTypedSelector } from "@theme/ApiItem/hooks";
12
15
 
@@ -22,6 +25,41 @@ function SecuritySchemes(props: any) {
22
25
  }
23
26
 
24
27
  const selectedAuth = options[selected];
28
+
29
+ const keyTranslations: Record<string, { id: string; message: string }> = {
30
+ description: {
31
+ id: OPENAPI_SECURITY_SCHEMES.DESCRIPTION,
32
+ message: "description:",
33
+ },
34
+ scheme: {
35
+ id: OPENAPI_SECURITY_SCHEMES.SCHEME,
36
+ message: "scheme:",
37
+ },
38
+ bearerFormat: {
39
+ id: OPENAPI_SECURITY_SCHEMES.BEARER_FORMAT,
40
+ message: "bearerFormat:",
41
+ },
42
+ openIdConnectUrl: {
43
+ id: OPENAPI_SECURITY_SCHEMES.OPEN_ID_CONNECT_URL,
44
+ message: "openIdConnectUrl:",
45
+ },
46
+ };
47
+
48
+ const renderRest = (rest: Record<string, any>) =>
49
+ Object.keys(rest).map((k) => {
50
+ const translation = keyTranslations[k];
51
+ const label = translation
52
+ ? translate({ id: translation.id, message: translation.message })
53
+ : `${k}:`;
54
+ return (
55
+ <span key={k}>
56
+ <strong>{label} </strong>
57
+ {typeof rest[k] === "object"
58
+ ? JSON.stringify(rest[k], null, 2)
59
+ : String(rest[k])}
60
+ </span>
61
+ );
62
+ });
25
63
  return (
26
64
  <details className="openapi-security__details" open={false}>
27
65
  <summary className="openapi-security__summary-container">
@@ -48,31 +86,37 @@ function SecuritySchemes(props: any) {
48
86
  }}
49
87
  >
50
88
  <span>
51
- <strong>name:</strong>{" "}
89
+ <strong>
90
+ {translate({
91
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
92
+ message: "name:",
93
+ })}
94
+ </strong>{" "}
52
95
  <Link to={infoAuthPath}>{name ?? key}</Link>
53
96
  </span>
54
97
  <span>
55
- <strong>type: </strong>
98
+ <strong>
99
+ {translate({
100
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
101
+ message: "type:",
102
+ })}
103
+ </strong>{" "}
56
104
  {type}
57
105
  </span>
58
106
  {scopes && scopes.length > 0 && (
59
107
  <span>
60
- <strong>scopes: </strong>
108
+ <strong>
109
+ {translate({
110
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
111
+ message: "scopes:",
112
+ })}
113
+ </strong>{" "}
61
114
  <code>
62
115
  {auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
63
116
  </code>
64
117
  </span>
65
118
  )}
66
- {Object.keys(rest).map((k, i) => {
67
- return (
68
- <span key={k}>
69
- <strong>{k}: </strong>
70
- {typeof rest[k] === "object"
71
- ? JSON.stringify(rest[k], null, 2)
72
- : String(rest[k])}
73
- </span>
74
- );
75
- })}
119
+ {renderRest(rest)}
76
120
  </pre>
77
121
  </React.Fragment>
78
122
  );
@@ -89,31 +133,37 @@ function SecuritySchemes(props: any) {
89
133
  }}
90
134
  >
91
135
  <span>
92
- <strong>name:</strong>{" "}
136
+ <strong>
137
+ {translate({
138
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
139
+ message: "name:",
140
+ })}
141
+ </strong>{" "}
93
142
  <Link to={infoAuthPath}>{name ?? key}</Link>
94
143
  </span>
95
144
  <span>
96
- <strong>type: </strong>
145
+ <strong>
146
+ {translate({
147
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
148
+ message: "type:",
149
+ })}
150
+ </strong>{" "}
97
151
  {type}
98
152
  </span>
99
153
  {scopes && scopes.length > 0 && (
100
154
  <span>
101
- <strong>scopes: </strong>
155
+ <strong>
156
+ {translate({
157
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
158
+ message: "scopes:",
159
+ })}
160
+ </strong>{" "}
102
161
  <code>
103
162
  {auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
104
163
  </code>
105
164
  </span>
106
165
  )}
107
- {Object.keys(rest).map((k, i) => {
108
- return (
109
- <span key={k}>
110
- <strong>{k}: </strong>
111
- {typeof rest[k] === "object"
112
- ? JSON.stringify(rest[k], null, 2)
113
- : String(rest[k])}
114
- </span>
115
- );
116
- })}
166
+ {renderRest(rest)}
117
167
  </pre>
118
168
  </React.Fragment>
119
169
  );
@@ -128,15 +178,30 @@ function SecuritySchemes(props: any) {
128
178
  }}
129
179
  >
130
180
  <span>
131
- <strong>name:</strong>{" "}
181
+ <strong>
182
+ {translate({
183
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
184
+ message: "name:",
185
+ })}
186
+ </strong>{" "}
132
187
  <Link to={infoAuthPath}>{auth.name ?? auth.key}</Link>
133
188
  </span>
134
189
  <span>
135
- <strong>type: </strong>
190
+ <strong>
191
+ {translate({
192
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
193
+ message: "type:",
194
+ })}
195
+ </strong>{" "}
136
196
  {auth.type}
137
197
  </span>
138
198
  <span>
139
- <strong>in: </strong>
199
+ <strong>
200
+ {translate({
201
+ id: OPENAPI_SECURITY_SCHEMES.IN,
202
+ message: "in:",
203
+ })}
204
+ </strong>{" "}
140
205
  {auth.in}
141
206
  </span>
142
207
  </pre>
@@ -156,31 +221,37 @@ function SecuritySchemes(props: any) {
156
221
  }}
157
222
  >
158
223
  <span>
159
- <strong>name:</strong>{" "}
224
+ <strong>
225
+ {translate({
226
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
227
+ message: "name:",
228
+ })}
229
+ </strong>{" "}
160
230
  <Link to={infoAuthPath}>{name ?? key}</Link>
161
231
  </span>
162
232
  <span>
163
- <strong>type: </strong>
233
+ <strong>
234
+ {translate({
235
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
236
+ message: "type:",
237
+ })}
238
+ </strong>{" "}
164
239
  {type}
165
240
  </span>
166
241
  {scopes && scopes.length > 0 && (
167
242
  <span>
168
- <strong>scopes: </strong>
243
+ <strong>
244
+ {translate({
245
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
246
+ message: "scopes:",
247
+ })}
248
+ </strong>{" "}
169
249
  <code>
170
250
  {auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
171
251
  </code>
172
252
  </span>
173
253
  )}
174
- {Object.keys(rest).map((k, i) => {
175
- return (
176
- <span key={k}>
177
- <strong>{k}: </strong>
178
- {typeof rest[k] === "object"
179
- ? JSON.stringify(rest[k], null, 2)
180
- : String(rest[k])}
181
- </span>
182
- );
183
- })}
254
+ {renderRest(rest)}
184
255
  </pre>
185
256
  </React.Fragment>
186
257
  );
@@ -198,35 +269,46 @@ function SecuritySchemes(props: any) {
198
269
  }}
199
270
  >
200
271
  <span>
201
- <strong>name:</strong>{" "}
272
+ <strong>
273
+ {translate({
274
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
275
+ message: "name:",
276
+ })}
277
+ </strong>{" "}
202
278
  <Link to={infoAuthPath}>{name ?? key}</Link>
203
279
  </span>
204
280
  <span>
205
- <strong>type: </strong>
281
+ <strong>
282
+ {translate({
283
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
284
+ message: "type:",
285
+ })}
286
+ </strong>{" "}
206
287
  {type}
207
288
  </span>
208
289
  {scopes && scopes.length > 0 && (
209
290
  <span>
210
- <strong>scopes: </strong>
291
+ <strong>
292
+ {translate({
293
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
294
+ message: "scopes:",
295
+ })}
296
+ </strong>{" "}
211
297
  <code>
212
298
  {auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
213
299
  </code>
214
300
  </span>
215
301
  )}
216
- {Object.keys(rest).map((k, i) => {
217
- return (
218
- <span key={k}>
219
- <strong>{k}: </strong>
220
- {typeof rest[k] === "object"
221
- ? JSON.stringify(rest[k], null, 2)
222
- : String(rest[k])}
223
- </span>
224
- );
225
- })}
302
+ {renderRest(rest)}
226
303
  {flows && (
227
304
  <span>
228
305
  <code>
229
- <strong>flows: </strong>
306
+ <strong>
307
+ {translate({
308
+ id: OPENAPI_SECURITY_SCHEMES.FLOWS,
309
+ message: "flows:",
310
+ })}
311
+ </strong>{" "}
230
312
  {JSON.stringify(flows, null, 2)}
231
313
  </code>
232
314
  </span>
@@ -248,31 +330,37 @@ function SecuritySchemes(props: any) {
248
330
  }}
249
331
  >
250
332
  <span>
251
- <strong>name:</strong>{" "}
333
+ <strong>
334
+ {translate({
335
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
336
+ message: "name:",
337
+ })}
338
+ </strong>{" "}
252
339
  <Link to={infoAuthPath}>{name ?? key}</Link>
253
340
  </span>
254
341
  <span>
255
- <strong>type: </strong>
342
+ <strong>
343
+ {translate({
344
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
345
+ message: "type:",
346
+ })}
347
+ </strong>{" "}
256
348
  {type}
257
349
  </span>
258
350
  {scopes && scopes.length > 0 && (
259
351
  <span>
260
- <strong>scopes: </strong>
352
+ <strong>
353
+ {translate({
354
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
355
+ message: "scopes:",
356
+ })}
357
+ </strong>{" "}
261
358
  <code>
262
359
  {auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
263
360
  </code>
264
361
  </span>
265
362
  )}
266
- {Object.keys(rest).map((k, i) => {
267
- return (
268
- <span key={k}>
269
- <strong>{k}: </strong>
270
- {typeof rest[k] === "object"
271
- ? JSON.stringify(rest[k], null, 2)
272
- : String(rest[k])}
273
- </span>
274
- );
275
- })}
363
+ {renderRest(rest)}
276
364
  </pre>
277
365
  </React.Fragment>
278
366
  );
@@ -7,11 +7,13 @@
7
7
 
8
8
  import React, { useState } from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
10
11
  import FloatingButton from "@theme/ApiExplorer/FloatingButton";
11
12
  import FormItem from "@theme/ApiExplorer/FormItem";
12
13
  import FormSelect from "@theme/ApiExplorer/FormSelect";
13
14
  import FormTextInput from "@theme/ApiExplorer/FormTextInput";
14
15
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
16
+ import { OPENAPI_SERVER } from "@theme/translationIds";
15
17
 
16
18
  import { setServer, setServerVariable } from "./slice";
17
19
 
@@ -57,7 +59,10 @@ function Server() {
57
59
  }
58
60
  }
59
61
  return (
60
- <FloatingButton onClick={() => setIsEditing(true)} label="Edit">
62
+ <FloatingButton
63
+ onClick={() => setIsEditing(true)}
64
+ label={translate({ id: OPENAPI_SERVER.EDIT_BUTTON, message: "Edit" })}
65
+ >
61
66
  <FormItem>
62
67
  <span className="openapi-explorer__server-url" title={url}>
63
68
  {url}
@@ -68,11 +73,14 @@ function Server() {
68
73
  }
69
74
  return (
70
75
  <div className="openapi-explorer__server-container">
71
- <FloatingButton onClick={() => setIsEditing(false)} label="Hide">
76
+ <FloatingButton
77
+ onClick={() => setIsEditing(false)}
78
+ label={translate({ id: OPENAPI_SERVER.HIDE_BUTTON, message: "Hide" })}
79
+ >
72
80
  <FormItem>
73
81
  <FormSelect
74
82
  options={options.map((s: any) => s.url)}
75
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
83
+ onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
76
84
  dispatch(
77
85
  setServer(
78
86
  JSON.stringify(
@@ -94,7 +102,7 @@ function Server() {
94
102
  <FormItem label={key}>
95
103
  <FormSelect
96
104
  options={value.variables[key].enum}
97
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
105
+ onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
98
106
  dispatch(
99
107
  setServerVariable(
100
108
  JSON.stringify({ key, value: e.target.value })
@@ -55,20 +55,10 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
55
55
  }
56
56
  }
57
57
 
58
- const decodedValue = decodeURI(param.value);
59
- const tryJson = () => {
60
- try {
61
- return JSON.parse(decodedValue);
62
- } catch (e) {
63
- return false;
64
- }
65
- };
66
-
67
- const jsonResult = tryJson();
68
-
69
58
  // Handle object values
70
- if (jsonResult && typeof jsonResult === "object") {
71
- if (param.style === "deepObject") {
59
+ if (param.style === "deepObject") {
60
+ const jsonResult = tryDecodeJsonParam(param.value);
61
+ if (jsonResult && typeof jsonResult === "object") {
72
62
  return Object.entries(jsonResult).map(
73
63
  ([key, val]) =>
74
64
  new sdk.QueryParam({
@@ -76,7 +66,10 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
76
66
  value: String(val),
77
67
  })
78
68
  );
79
- } else if (param.explode) {
69
+ }
70
+ } else if (param.explode) {
71
+ const jsonResult = tryDecodeJsonParam(param.value);
72
+ if (jsonResult && typeof jsonResult === "object") {
80
73
  return Object.entries(jsonResult).map(
81
74
  ([key, val]) =>
82
75
  new sdk.QueryParam({
@@ -94,17 +87,9 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
94
87
  }
95
88
  }
96
89
 
97
- // Handle boolean values
98
- if (typeof decodedValue === "boolean") {
99
- return new sdk.QueryParam({
100
- key: param.name,
101
- value: decodedValue ? "true" : "false",
102
- });
103
- }
104
-
105
90
  // Parameter allows empty value: "/hello?extended"
106
91
  if (param.allowEmptyValue) {
107
- if (decodedValue === "true") {
92
+ if (param.value === "true") {
108
93
  return new sdk.QueryParam({
109
94
  key: param.name,
110
95
  value: null,
@@ -150,18 +135,9 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
150
135
  });
151
136
  }
152
137
 
153
- const decodedValue = decodeURI(param.value);
154
- const tryJson = () => {
155
- try {
156
- return JSON.parse(decodedValue);
157
- } catch (e) {
158
- return false;
159
- }
160
- };
138
+ const jsonResult = tryDecodeJsonParam(param.value);
161
139
 
162
- const jsonResult = tryJson();
163
-
164
- if (typeof jsonResult === "object") {
140
+ if (jsonResult && typeof jsonResult === "object") {
165
141
  if (param.style === "matrix") {
166
142
  serializedValue = Object.entries(jsonResult)
167
143
  .map(([key, val]) => `;${key}=${val}`)
@@ -172,7 +148,7 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
172
148
  .join(",");
173
149
  }
174
150
  } else {
175
- serializedValue = decodedValue || `:${param.name}`;
151
+ serializedValue = param.value;
176
152
  }
177
153
 
178
154
  return new sdk.Variable({
@@ -191,17 +167,8 @@ function buildCookie(cookieParams: Param[]) {
191
167
  const cookies = cookieParams
192
168
  .map((param) => {
193
169
  if (param.value) {
194
- const decodedValue = decodeURI(param.value as string);
195
- const tryJson = () => {
196
- try {
197
- return JSON.parse(decodedValue);
198
- } catch (e) {
199
- return false;
200
- }
201
- };
202
-
203
- const jsonResult = tryJson();
204
- if (typeof jsonResult === "object") {
170
+ const jsonResult = tryDecodeJsonParam(param.value as string);
171
+ if (jsonResult && typeof jsonResult === "object") {
205
172
  if (param.style === "form") {
206
173
  // Handle form style
207
174
  if (param.explode) {
@@ -266,16 +233,9 @@ function setHeaders(
266
233
 
267
234
  headerParams.forEach((param) => {
268
235
  if (param.value) {
269
- const decodedValue = decodeURI(param.value as string);
270
- const tryJson = () => {
271
- try {
272
- return JSON.parse(decodedValue);
273
- } catch (e) {
274
- return false;
275
- }
276
- };
277
-
278
- const jsonResult = tryJson();
236
+ const jsonResult = Array.isArray(param.value)
237
+ ? param.value.map(tryDecodeJsonParam)
238
+ : tryDecodeJsonParam(param.value);
279
239
  if (Array.isArray(param.value)) {
280
240
  if (param.style === "simple") {
281
241
  if (param.explode) {
@@ -324,6 +284,14 @@ function setHeaders(
324
284
  }
325
285
  }
326
286
 
287
+ function tryDecodeJsonParam(value: string): any {
288
+ try {
289
+ return JSON.parse(decodeURI(value));
290
+ } catch (e) {
291
+ return false;
292
+ }
293
+ }
294
+
327
295
  // TODO: this is all a bit hacky
328
296
  function setBody(clonedPostman: sdk.Request, body: Body) {
329
297
  if (clonedPostman.body === undefined) {
@@ -345,7 +313,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
345
313
  switch (clonedPostman.body.mode) {
346
314
  case "raw": {
347
315
  // check file even though it should already be set from above
348
- if (body.type !== "raw" || body.content?.type === "file") {
316
+ if (
317
+ body.type !== "raw" ||
318
+ body.content?.type === "file" ||
319
+ body.content?.type === "file[]"
320
+ ) {
349
321
  clonedPostman.body = undefined;
350
322
  return;
351
323
  }
@@ -360,15 +332,23 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
360
332
  clonedPostman.body.raw = `${body.content?.value}`;
361
333
  return;
362
334
  }
363
- const params = Object.entries(body.content)
335
+ const params: sdk.FormParam[] = [];
336
+ Object.entries(body.content)
364
337
  .filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
365
- .map(([key, content]) => {
338
+ .forEach(([key, content]) => {
366
339
  if (content.type === "file") {
367
- return new sdk.FormParam({ key: key, ...content });
340
+ params.push(new sdk.FormParam({ key: key, ...content }));
341
+ } else if (content.type === "file[]") {
342
+ content.value.forEach((file) =>
343
+ params.push(new sdk.FormParam({ key, value: file }))
344
+ );
345
+ } else {
346
+ params.push(new sdk.FormParam({ key: key, value: content.value }));
368
347
  }
369
- return new sdk.FormParam({ key: key, value: content.value });
370
348
  });
371
- clonedPostman.body.formdata?.assimilate(params, false);
349
+ params.forEach((param) => {
350
+ clonedPostman.body?.formdata?.add(param);
351
+ });
372
352
  return;
373
353
  }
374
354
  case "urlencoded": {
@@ -382,7 +362,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
382
362
  const params = Object.entries(body.content)
383
363
  .filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
384
364
  .map(([key, content]) => {
385
- if (content.type !== "file" && content.value) {
365
+ if (
366
+ content.type !== "file" &&
367
+ content.type !== "file[]" &&
368
+ content.value
369
+ ) {
386
370
  return new sdk.QueryParam({ key: key, value: content.value });
387
371
  }
388
372
  return undefined;
@@ -7,6 +7,7 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { useDoc } from "@docusaurus/plugin-content-docs/client";
10
11
  import CodeSnippets from "@theme/ApiExplorer/CodeSnippets";
11
12
  import Request from "@theme/ApiExplorer/Request";
12
13
  import Response from "@theme/ApiExplorer/Response";
@@ -21,6 +22,9 @@ function ApiExplorer({
21
22
  item: NonNullable<ApiItem>;
22
23
  infoPath: string;
23
24
  }) {
25
+ const metadata = useDoc();
26
+ const { mask_credentials } = metadata.frontMatter;
27
+
24
28
  const postman = new sdk.Request(
25
29
  item.postman
26
30
  ? sdk.Request.isRequest(item.postman)
@@ -36,6 +40,7 @@ function ApiExplorer({
36
40
  <CodeSnippets
37
41
  postman={postman}
38
42
  codeSamples={(item as any)["x-codeSamples"] ?? []}
43
+ maskCredentials={mask_credentials}
39
44
  />
40
45
  )}
41
46
  <Request item={item} />
@@ -5,25 +5,29 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { Middleware } from "@reduxjs/toolkit";
8
+ import type { Middleware } from "@reduxjs/toolkit";
9
9
  import {
10
10
  setAuthData,
11
11
  setSelectedAuth,
12
12
  } from "@theme/ApiExplorer/Authorization/slice";
13
- import { AppDispatch, RootState } from "@theme/ApiItem/store";
14
- /* eslint-disable import/no-extraneous-dependencies*/
15
- import { ThemeConfig } from "docusaurus-theme-openapi-docs/src/types";
13
+ import type { AppDispatch, RootState } from "@theme/ApiItem/store";
14
+ import type { ServerObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
15
+ import type { ThemeConfig } from "docusaurus-theme-openapi-docs/src/types";
16
16
 
17
17
  import { createStorage, hashArray } from "./storage-utils";
18
18
 
19
- export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
20
- const persistanceMiddleware: Middleware<{}, RootState, AppDispatch> =
21
- (storeAPI) => (next) => (action) => {
19
+ export function createPersistenceMiddleware(options: ThemeConfig["api"]) {
20
+ const persistenceMiddleware: Middleware<{}, RootState, AppDispatch> =
21
+ (storeAPI) =>
22
+ (next) =>
23
+ (action: ReturnType<typeof setAuthData | typeof setSelectedAuth> | any) => {
22
24
  const result = next(action);
23
25
 
24
26
  const state = storeAPI.getState();
25
27
 
26
- const storage = createStorage("sessionStorage");
28
+ const storage = createStorage(
29
+ options?.authPersistence ?? "sessionStorage"
30
+ );
27
31
 
28
32
  if (action.type === setAuthData.type) {
29
33
  for (const [key, value] of Object.entries(state.auth.data)) {
@@ -58,14 +62,20 @@ export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
58
62
  }
59
63
 
60
64
  if (action.type === "server/setServerVariable") {
61
- const server = storage.getItem("server") ?? "{}";
65
+ const server = storage.getItem("server");
66
+ if (!server) {
67
+ return result;
68
+ }
62
69
  const variables = JSON.parse(action.payload);
63
- let serverObject = JSON.parse(server);
64
- serverObject.variables[variables.key].default = variables.value;
65
- storage.setItem("server", JSON.stringify(serverObject));
70
+
71
+ const serverObject = (JSON.parse(server) as ServerObject) ?? {};
72
+ if (serverObject.variables?.[variables.key]) {
73
+ serverObject.variables[variables.key].default = variables.value;
74
+ storage.setItem("server", JSON.stringify(serverObject));
75
+ }
66
76
  }
67
77
 
68
78
  return result;
69
79
  };
70
- return persistanceMiddleware;
80
+ return persistenceMiddleware;
71
81
  }