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
@@ -5,29 +5,86 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
+ var __createBinding =
9
+ (this && this.__createBinding) ||
10
+ (Object.create
11
+ ? function (o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (
15
+ !desc ||
16
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
17
+ ) {
18
+ desc = {
19
+ enumerable: true,
20
+ get: function () {
21
+ return m[k];
22
+ },
23
+ };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }
27
+ : function (o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ });
31
+ var __setModuleDefault =
32
+ (this && this.__setModuleDefault) ||
33
+ (Object.create
34
+ ? function (o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }
37
+ : function (o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar =
41
+ (this && this.__importStar) ||
42
+ (function () {
43
+ var ownKeys = function (o) {
44
+ ownKeys =
45
+ Object.getOwnPropertyNames ||
46
+ function (o) {
47
+ var ar = [];
48
+ for (var k in o)
49
+ if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
50
+ return ar;
51
+ };
52
+ return ownKeys(o);
53
+ };
54
+ return function (mod) {
55
+ if (mod && mod.__esModule) return mod;
56
+ var result = {};
57
+ if (mod != null)
58
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++)
59
+ if (k[i] !== "default") __createBinding(result, mod, k[i]);
60
+ __setModuleDefault(result, mod);
61
+ return result;
62
+ };
63
+ })();
8
64
  var __importDefault =
9
65
  (this && this.__importDefault) ||
10
66
  function (mod) {
11
67
  return mod && mod.__esModule ? mod : { default: mod };
12
68
  };
13
69
  Object.defineProperty(exports, "__esModule", { value: true });
14
- const react_1 = __importDefault(require("react"));
70
+ const react_1 = __importStar(require("react"));
71
+ const Translate_1 = require("@docusaurus/Translate");
15
72
  const json2xml_1 = __importDefault(require("@theme/ApiExplorer/Body/json2xml"));
16
73
  const FormFileUpload_1 = __importDefault(
17
74
  require("@theme/ApiExplorer/FormFileUpload")
18
75
  );
19
76
  const FormItem_1 = __importDefault(require("@theme/ApiExplorer/FormItem"));
20
- const FormSelect_1 = __importDefault(require("@theme/ApiExplorer/FormSelect"));
21
- const FormTextInput_1 = __importDefault(
22
- require("@theme/ApiExplorer/FormTextInput")
23
- );
24
77
  const LiveEditor_1 = __importDefault(require("@theme/ApiExplorer/LiveEditor"));
25
78
  const hooks_1 = require("@theme/ApiItem/hooks");
26
79
  const Markdown_1 = __importDefault(require("@theme/Markdown"));
27
80
  const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
28
81
  const TabItem_1 = __importDefault(require("@theme/TabItem"));
82
+ const translationIds_1 = require("@theme/translationIds");
83
+ const createSchemaExample_1 = require("docusaurus-plugin-openapi-docs/src/openapi/createSchemaExample");
29
84
  const xml_formatter_1 = __importDefault(require("xml-formatter"));
30
85
  const slice_1 = require("./slice");
86
+ const FormBodyItem_1 = __importDefault(require("./FormBodyItem"));
87
+ const resolveSchemaWithSelections_1 = require("./resolveSchemaWithSelections");
31
88
  function BodyWrap({
32
89
  requestBodyMetadata,
33
90
  jsonRequestBodyExample,
@@ -58,6 +115,9 @@ function Body({
58
115
  const contentType = (0, hooks_1.useTypedSelector)(
59
116
  (state) => state.contentType.value
60
117
  );
118
+ const schemaSelections = (0, hooks_1.useTypedSelector)(
119
+ (state) => state.schemaSelection?.selections ?? {}
120
+ );
61
121
  const dispatch = (0, hooks_1.useTypedDispatch)();
62
122
  // Lot's of possible content-types:
63
123
  // - application/json
@@ -77,15 +137,211 @@ function Body({
77
137
  // Show form:
78
138
  // - multipart/form-data
79
139
  // - application/x-www-form-urlencoded
80
- const schema = requestBodyMetadata?.content?.[contentType]?.schema;
140
+ const rawSchema = requestBodyMetadata?.content?.[contentType]?.schema;
81
141
  const example = requestBodyMetadata?.content?.[contentType]?.example;
82
142
  const examples = requestBodyMetadata?.content?.[contentType]?.examples;
143
+ // Resolve the schema based on user's anyOf/oneOf tab selections
144
+ const schema = (0, react_1.useMemo)(() => {
145
+ if (!rawSchema) return rawSchema;
146
+ return (0, resolveSchemaWithSelections_1.resolveSchemaWithSelections)(
147
+ rawSchema,
148
+ schemaSelections,
149
+ "requestBody"
150
+ );
151
+ }, [rawSchema, schemaSelections]);
152
+ // OpenAPI 3.1 / JSON Schema: schema.examples is an array of example values
153
+ const schemaExamples = schema?.examples;
154
+ // Compute the default body based on content type and schema
155
+ // This needs to be computed before early returns so the useEffect can use it
156
+ const { defaultBody, exampleBody, examplesBodies, language } = (0,
157
+ react_1.useMemo)(() => {
158
+ let lang = "plaintext";
159
+ let defBody = "";
160
+ let exBody;
161
+ let exBodies = [];
162
+ // Skip body generation for binary and form content types
163
+ if (schema?.format === "binary") {
164
+ return {
165
+ defaultBody: defBody,
166
+ exampleBody: exBody,
167
+ examplesBodies: exBodies,
168
+ language: lang,
169
+ };
170
+ }
171
+ if (
172
+ (contentType === "multipart/form-data" ||
173
+ contentType === "application/x-www-form-urlencoded") &&
174
+ schema?.type === "object"
175
+ ) {
176
+ return {
177
+ defaultBody: defBody,
178
+ exampleBody: exBody,
179
+ examplesBodies: exBodies,
180
+ language: lang,
181
+ };
182
+ }
183
+ // Generate example from the schema for the current content type
184
+ let contentTypeExample;
185
+ if (schema) {
186
+ contentTypeExample = (0, createSchemaExample_1.sampleFromSchema)(schema, {
187
+ type: "request",
188
+ });
189
+ } else if (jsonRequestBodyExample) {
190
+ // Fallback to the build-time generated example if no schema is available
191
+ contentTypeExample = jsonRequestBodyExample;
192
+ }
193
+ if (
194
+ contentType?.includes("application/json") ||
195
+ contentType?.endsWith("+json")
196
+ ) {
197
+ if (contentTypeExample) {
198
+ defBody = JSON.stringify(contentTypeExample, null, 2);
199
+ }
200
+ if (example) {
201
+ exBody = JSON.stringify(example, null, 2);
202
+ }
203
+ if (examples) {
204
+ for (const [key, ex] of Object.entries(examples)) {
205
+ let body = ex.value;
206
+ try {
207
+ // If the value is already valid JSON we shouldn't double encode the value
208
+ JSON.parse(ex.value);
209
+ } catch (e) {
210
+ body = JSON.stringify(ex.value, null, 2);
211
+ }
212
+ exBodies.push({
213
+ label: key,
214
+ body,
215
+ summary: ex.summary,
216
+ });
217
+ }
218
+ }
219
+ // OpenAPI 3.1: schema.examples is an array of example values
220
+ if (schemaExamples && Array.isArray(schemaExamples)) {
221
+ schemaExamples.forEach((schemaExample, index) => {
222
+ const body = JSON.stringify(schemaExample, null, 2);
223
+ exBodies.push({
224
+ label: `Example ${index + 1}`,
225
+ body,
226
+ summary: undefined,
227
+ });
228
+ });
229
+ }
230
+ lang = "json";
231
+ }
232
+ if (contentType === "application/xml" || contentType?.endsWith("+xml")) {
233
+ if (contentTypeExample) {
234
+ try {
235
+ defBody = (0, xml_formatter_1.default)(
236
+ (0, json2xml_1.default)(contentTypeExample, ""),
237
+ {
238
+ indentation: " ",
239
+ lineSeparator: "\n",
240
+ collapseContent: true,
241
+ }
242
+ );
243
+ } catch {
244
+ defBody = (0, json2xml_1.default)(contentTypeExample);
245
+ }
246
+ }
247
+ if (example) {
248
+ try {
249
+ exBody = (0, xml_formatter_1.default)(
250
+ (0, json2xml_1.default)(example, ""),
251
+ {
252
+ indentation: " ",
253
+ lineSeparator: "\n",
254
+ collapseContent: true,
255
+ }
256
+ );
257
+ } catch {
258
+ exBody = (0, json2xml_1.default)(example);
259
+ }
260
+ }
261
+ if (examples) {
262
+ for (const [key, ex] of Object.entries(examples)) {
263
+ let formattedXmlBody;
264
+ try {
265
+ formattedXmlBody = (0, xml_formatter_1.default)(ex.value, {
266
+ indentation: " ",
267
+ lineSeparator: "\n",
268
+ collapseContent: true,
269
+ });
270
+ } catch {
271
+ formattedXmlBody = ex.value;
272
+ }
273
+ exBodies.push({
274
+ label: key,
275
+ body: formattedXmlBody,
276
+ summary: ex.summary,
277
+ });
278
+ }
279
+ }
280
+ // OpenAPI 3.1: schema.examples is an array of example values
281
+ if (schemaExamples && Array.isArray(schemaExamples)) {
282
+ schemaExamples.forEach((schemaExample, index) => {
283
+ let formattedXmlBody;
284
+ try {
285
+ formattedXmlBody = (0, xml_formatter_1.default)(
286
+ (0, json2xml_1.default)(schemaExample, ""),
287
+ {
288
+ indentation: " ",
289
+ lineSeparator: "\n",
290
+ collapseContent: true,
291
+ }
292
+ );
293
+ } catch {
294
+ formattedXmlBody = (0, json2xml_1.default)(schemaExample);
295
+ }
296
+ exBodies.push({
297
+ label: `Example ${index + 1}`,
298
+ body: formattedXmlBody,
299
+ summary: undefined,
300
+ });
301
+ });
302
+ }
303
+ lang = "xml";
304
+ }
305
+ return {
306
+ defaultBody: defBody,
307
+ exampleBody: exBody,
308
+ examplesBodies: exBodies,
309
+ language: lang,
310
+ };
311
+ }, [
312
+ schema,
313
+ contentType,
314
+ example,
315
+ examples,
316
+ schemaExamples,
317
+ jsonRequestBodyExample,
318
+ ]);
319
+ // Create a stable key for the LiveApp component that changes when schema selection changes
320
+ // This forces the editor to remount and pick up the new defaultBody
321
+ const schemaSelectionKey = (0, react_1.useMemo)(
322
+ () => JSON.stringify(schemaSelections),
323
+ [schemaSelections]
324
+ );
325
+ // Update body in Redux when content type or schema selection changes
326
+ (0, react_1.useEffect)(() => {
327
+ if (defaultBody) {
328
+ dispatch((0, slice_1.setStringRawBody)(defaultBody));
329
+ }
330
+ // Re-run when contentType, schemaSelections, or defaultBody change
331
+ // eslint-disable-next-line react-hooks/exhaustive-deps
332
+ }, [contentType, schemaSelections, defaultBody]);
333
+ // Now handle early returns after all hooks have been called
83
334
  if (schema?.format === "binary") {
84
335
  return react_1.default.createElement(
85
336
  FormItem_1.default,
86
337
  null,
87
338
  react_1.default.createElement(FormFileUpload_1.default, {
88
- placeholder: schema.description || "Body",
339
+ placeholder:
340
+ schema.description ||
341
+ (0, Translate_1.translate)({
342
+ id: translationIds_1.OPENAPI_REQUEST.BODY_TITLE,
343
+ message: "Body",
344
+ }),
89
345
  onChange: (file) => {
90
346
  if (file === undefined) {
91
347
  dispatch((0, slice_1.clearRawBody)());
@@ -109,177 +365,23 @@ function Body({
109
365
  return react_1.default.createElement(
110
366
  FormItem_1.default,
111
367
  { className: "openapi-explorer__form-item-body-container" },
112
- react_1.default.createElement(
113
- "div",
114
- null,
115
- Object.entries(schema.properties ?? {}).map(([key, val]) => {
116
- if (val.format === "binary") {
117
- return react_1.default.createElement(
118
- FormItem_1.default,
119
- {
120
- key: key,
121
- label: key,
122
- required:
123
- Array.isArray(schema.required) &&
124
- schema.required.includes(key),
125
- },
126
- react_1.default.createElement(FormFileUpload_1.default, {
127
- placeholder: val.description || key,
128
- onChange: (file) => {
129
- if (file === undefined) {
130
- dispatch((0, slice_1.clearFormBodyKey)(key));
131
- return;
132
- }
133
- dispatch(
134
- (0, slice_1.setFileFormBody)({
135
- key: key,
136
- value: {
137
- src: `/path/to/${file.name}`,
138
- content: file,
139
- },
140
- })
141
- );
142
- },
143
- })
144
- );
145
- }
146
- if (val.enum) {
147
- return react_1.default.createElement(
148
- FormItem_1.default,
149
- {
150
- key: key,
151
- label: key,
152
- required:
153
- Array.isArray(schema.required) &&
154
- schema.required.includes(key),
155
- },
156
- react_1.default.createElement(FormSelect_1.default, {
157
- options: ["---", ...val.enum],
158
- onChange: (e) => {
159
- const val = e.target.value;
160
- if (val === "---") {
161
- dispatch((0, slice_1.clearFormBodyKey)(key));
162
- } else {
163
- dispatch(
164
- (0, slice_1.setStringFormBody)({
165
- key: key,
166
- value: val,
167
- })
168
- );
169
- }
170
- },
171
- })
172
- );
173
- }
174
- // TODO: support all the other types.
175
- return react_1.default.createElement(
176
- FormItem_1.default,
177
- {
178
- key: key,
179
- label: key,
180
- required:
181
- Array.isArray(schema.required) && schema.required.includes(key),
182
- },
183
- react_1.default.createElement(FormTextInput_1.default, {
184
- paramName: key,
185
- isRequired:
186
- Array.isArray(schema.required) && schema.required.includes(key),
187
- placeholder: val.description || key,
188
- onChange: (e) => {
189
- dispatch(
190
- (0, slice_1.setStringFormBody)({
191
- key: key,
192
- value: e.target.value,
193
- })
194
- );
195
- },
196
- })
197
- );
198
- })
199
- )
200
- );
201
- }
202
- let language = "plaintext";
203
- let defaultBody = ""; //"body content";
204
- let exampleBody;
205
- let examplesBodies = [];
206
- if (
207
- contentType.includes("application/json") ||
208
- contentType.endsWith("+json")
209
- ) {
210
- if (jsonRequestBodyExample) {
211
- defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
212
- }
213
- if (example) {
214
- exampleBody = JSON.stringify(example, null, 2);
215
- }
216
- if (examples) {
217
- for (const [key, example] of Object.entries(examples)) {
218
- let body = example.value;
219
- try {
220
- // If the value is already valid JSON we shouldn't double encode the value
221
- JSON.parse(example.value);
222
- } catch (e) {
223
- body = JSON.stringify(example.value, null, 2);
224
- }
225
- examplesBodies.push({
226
- label: key,
227
- body,
228
- summary: example.summary,
229
- });
230
- }
231
- }
232
- language = "json";
233
- }
234
- if (contentType === "application/xml" || contentType.endsWith("+xml")) {
235
- if (jsonRequestBodyExample) {
236
- try {
237
- defaultBody = (0, xml_formatter_1.default)(
238
- (0, json2xml_1.default)(jsonRequestBodyExample, ""),
368
+ Object.entries(schema.properties ?? {}).map(([key, val]) => {
369
+ return react_1.default.createElement(
370
+ FormItem_1.default,
239
371
  {
240
- indentation: " ",
241
- lineSeparator: "\n",
242
- collapseContent: true,
243
- }
244
- );
245
- } catch {
246
- defaultBody = (0, json2xml_1.default)(jsonRequestBodyExample);
247
- }
248
- }
249
- if (example) {
250
- try {
251
- exampleBody = (0, xml_formatter_1.default)(
252
- (0, json2xml_1.default)(example, ""),
253
- {
254
- indentation: " ",
255
- lineSeparator: "\n",
256
- collapseContent: true,
257
- }
372
+ key: key,
373
+ label: key,
374
+ required:
375
+ Array.isArray(schema.required) && schema.required.includes(key),
376
+ },
377
+ react_1.default.createElement(FormBodyItem_1.default, {
378
+ schemaObject: val,
379
+ id: key,
380
+ schema: schema,
381
+ })
258
382
  );
259
- } catch {
260
- exampleBody = (0, json2xml_1.default)(example);
261
- }
262
- }
263
- if (examples) {
264
- for (const [key, example] of Object.entries(examples)) {
265
- let formattedXmlBody;
266
- try {
267
- formattedXmlBody = (0, xml_formatter_1.default)(example.value, {
268
- indentation: " ",
269
- lineSeparator: "\n",
270
- collapseContent: true,
271
- });
272
- } catch {
273
- formattedXmlBody = example.value;
274
- }
275
- examplesBodies.push({
276
- label: key,
277
- body: formattedXmlBody,
278
- summary: example.summary,
279
- });
280
- }
281
- }
282
- language = "xml";
383
+ })
384
+ );
283
385
  }
284
386
  if (exampleBody) {
285
387
  return react_1.default.createElement(
@@ -291,13 +393,21 @@ function Body({
291
393
  react_1.default.createElement(
292
394
  TabItem_1.default,
293
395
  {
294
- label: "Example (from schema)",
396
+ label: (0, Translate_1.translate)({
397
+ id: translationIds_1.OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
398
+ message: "Example (from schema)",
399
+ }),
295
400
  value: "Example (from schema)",
296
401
  default: true,
297
402
  },
298
403
  react_1.default.createElement(
299
404
  LiveEditor_1.default,
300
- { action: dispatch, language: language, required: required },
405
+ {
406
+ key: `${contentType}-${schemaSelectionKey}`,
407
+ action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
408
+ language: language,
409
+ required: required,
410
+ },
301
411
  defaultBody
302
412
  )
303
413
  ),
@@ -313,7 +423,12 @@ function Body({
313
423
  exampleBody &&
314
424
  react_1.default.createElement(
315
425
  LiveEditor_1.default,
316
- { action: dispatch, language: language, required: required },
426
+ {
427
+ key: `${contentType}-example`,
428
+ action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
429
+ language: language,
430
+ required: required,
431
+ },
317
432
  exampleBody
318
433
  )
319
434
  )
@@ -330,37 +445,46 @@ function Body({
330
445
  react_1.default.createElement(
331
446
  TabItem_1.default,
332
447
  {
333
- label: "Example (from schema)",
448
+ label: (0, Translate_1.translate)({
449
+ id: translationIds_1.OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
450
+ message: "Example (from schema)",
451
+ }),
334
452
  value: "Example (from schema)",
335
453
  default: true,
336
454
  },
337
455
  react_1.default.createElement(
338
456
  LiveEditor_1.default,
339
- { action: dispatch, language: language, required: required },
457
+ {
458
+ key: `${contentType}-${schemaSelectionKey}`,
459
+ action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
460
+ language: language,
461
+ required: required,
462
+ },
340
463
  defaultBody
341
464
  )
342
465
  ),
343
- examplesBodies.map((example) => {
466
+ examplesBodies.map((ex) => {
344
467
  return (
345
468
  // @ts-ignore
346
469
  react_1.default.createElement(
347
470
  TabItem_1.default,
348
- {
349
- label: example.label,
350
- value: example.label,
351
- key: example.label,
352
- },
353
- example.summary &&
471
+ { label: ex.label, value: ex.label, key: ex.label },
472
+ ex.summary &&
354
473
  react_1.default.createElement(
355
474
  Markdown_1.default,
356
475
  null,
357
- example.summary
476
+ ex.summary
358
477
  ),
359
- example.body &&
478
+ ex.body &&
360
479
  react_1.default.createElement(
361
480
  LiveEditor_1.default,
362
- { action: dispatch, language: language },
363
- example.body
481
+ {
482
+ key: `${contentType}-${ex.label}`,
483
+ action: (code) =>
484
+ dispatch((0, slice_1.setStringRawBody)(code)),
485
+ language: language,
486
+ },
487
+ ex.body
364
488
  )
365
489
  )
366
490
  );
@@ -373,7 +497,12 @@ function Body({
373
497
  null,
374
498
  react_1.default.createElement(
375
499
  LiveEditor_1.default,
376
- { action: dispatch, language: language, required: required },
500
+ {
501
+ key: `${contentType}-${schemaSelectionKey}`,
502
+ action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
503
+ language: language,
504
+ required: required,
505
+ },
377
506
  defaultBody
378
507
  )
379
508
  );
@@ -0,0 +1,13 @@
1
+ import { SchemaObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
2
+ export interface SchemaSelections {
3
+ [schemaPath: string]: number;
4
+ }
5
+ /**
6
+ * Resolves a schema by replacing anyOf/oneOf with the selected option based on user selections.
7
+ *
8
+ * @param schema - The original schema object
9
+ * @param selections - Map of schema paths to selected indices
10
+ * @param basePath - The base path for this schema (used for looking up selections)
11
+ * @returns A new schema with anyOf/oneOf resolved to selected options
12
+ */
13
+ export declare function resolveSchemaWithSelections(schema: SchemaObject | undefined, selections: SchemaSelections, basePath?: string): SchemaObject | undefined;