docusaurus-theme-openapi-docs 4.6.0 → 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 (36) hide show
  1. package/lib/markdown/schema.js +5 -0
  2. package/lib/theme/ApiExplorer/Body/index.js +263 -128
  3. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.d.ts +13 -0
  4. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.js +133 -0
  5. package/lib/theme/ApiExplorer/SchemaSelection/index.d.ts +2 -0
  6. package/lib/theme/ApiExplorer/SchemaSelection/index.js +36 -0
  7. package/lib/theme/ApiExplorer/SchemaSelection/slice.d.ts +37 -0
  8. package/lib/theme/ApiExplorer/SchemaSelection/slice.js +39 -0
  9. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +2 -0
  10. package/lib/theme/ApiItem/hooks.d.ts +1 -0
  11. package/lib/theme/ApiItem/index.js +1 -0
  12. package/lib/theme/ApiItem/store.d.ts +6 -0
  13. package/lib/theme/ApiItem/store.js +6 -2
  14. package/lib/theme/RequestSchema/index.js +58 -52
  15. package/lib/theme/Schema/index.d.ts +6 -0
  16. package/lib/theme/Schema/index.js +135 -9
  17. package/lib/theme/SchemaTabs/index.d.ts +8 -1
  18. package/lib/theme/SchemaTabs/index.js +10 -1
  19. package/lib/theme/StatusCodes/index.d.ts +1 -1
  20. package/lib/theme/styles.scss +10 -0
  21. package/package.json +3 -3
  22. package/src/markdown/schema.ts +6 -0
  23. package/src/theme/ApiExplorer/Body/index.tsx +206 -122
  24. package/src/theme/ApiExplorer/Body/resolveSchemaWithSelections.ts +155 -0
  25. package/{lib/types.js → src/theme/ApiExplorer/SchemaSelection/index.ts} +7 -2
  26. package/src/theme/ApiExplorer/SchemaSelection/slice.ts +46 -0
  27. package/src/theme/ApiItem/index.tsx +1 -0
  28. package/src/theme/ApiItem/store.ts +2 -0
  29. package/src/theme/RequestSchema/index.tsx +49 -39
  30. package/src/theme/Schema/index.tsx +184 -27
  31. package/src/theme/SchemaTabs/index.tsx +15 -4
  32. package/src/theme/StatusCodes/index.tsx +1 -2
  33. package/src/theme/styles.scss +10 -0
  34. package/tsconfig.tsbuildinfo +1 -1
  35. package/lib/types.d.ts +0 -54
  36. /package/src/{types.ts → types.d.ts} +0 -0
@@ -11,6 +11,11 @@ exports.getQualifierMessage = getQualifierMessage;
11
11
  const Translate_1 = require("@docusaurus/Translate");
12
12
  const translationIds_1 = require("../theme/translationIds");
13
13
  function prettyName(schema, circular) {
14
+ // Handle enum-only schemas (valid in JSON Schema)
15
+ // When enum is present without explicit type, treat as string
16
+ if (schema.enum && !schema.type) {
17
+ return "string";
18
+ }
14
19
  if (schema.format) {
15
20
  return schema.format;
16
21
  }
@@ -5,13 +5,69 @@
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"));
15
71
  const Translate_1 = require("@docusaurus/Translate");
16
72
  const json2xml_1 = __importDefault(require("@theme/ApiExplorer/Body/json2xml"));
17
73
  const FormFileUpload_1 = __importDefault(
@@ -24,9 +80,11 @@ const Markdown_1 = __importDefault(require("@theme/Markdown"));
24
80
  const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
25
81
  const TabItem_1 = __importDefault(require("@theme/TabItem"));
26
82
  const translationIds_1 = require("@theme/translationIds");
83
+ const createSchemaExample_1 = require("docusaurus-plugin-openapi-docs/src/openapi/createSchemaExample");
27
84
  const xml_formatter_1 = __importDefault(require("xml-formatter"));
28
85
  const slice_1 = require("./slice");
29
86
  const FormBodyItem_1 = __importDefault(require("./FormBodyItem"));
87
+ const resolveSchemaWithSelections_1 = require("./resolveSchemaWithSelections");
30
88
  function BodyWrap({
31
89
  requestBodyMetadata,
32
90
  jsonRequestBodyExample,
@@ -57,6 +115,9 @@ function Body({
57
115
  const contentType = (0, hooks_1.useTypedSelector)(
58
116
  (state) => state.contentType.value
59
117
  );
118
+ const schemaSelections = (0, hooks_1.useTypedSelector)(
119
+ (state) => state.schemaSelection?.selections ?? {}
120
+ );
60
121
  const dispatch = (0, hooks_1.useTypedDispatch)();
61
122
  // Lot's of possible content-types:
62
123
  // - application/json
@@ -76,11 +137,200 @@ function Body({
76
137
  // Show form:
77
138
  // - multipart/form-data
78
139
  // - application/x-www-form-urlencoded
79
- const schema = requestBodyMetadata?.content?.[contentType]?.schema;
140
+ const rawSchema = requestBodyMetadata?.content?.[contentType]?.schema;
80
141
  const example = requestBodyMetadata?.content?.[contentType]?.example;
81
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]);
82
152
  // OpenAPI 3.1 / JSON Schema: schema.examples is an array of example values
83
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
84
334
  if (schema?.format === "binary") {
85
335
  return react_1.default.createElement(
86
336
  FormItem_1.default,
@@ -133,122 +383,6 @@ function Body({
133
383
  })
134
384
  );
135
385
  }
136
- let language = "plaintext";
137
- let defaultBody = ""; //"body content";
138
- let exampleBody;
139
- let examplesBodies = [];
140
- if (
141
- contentType.includes("application/json") ||
142
- contentType.endsWith("+json")
143
- ) {
144
- if (jsonRequestBodyExample) {
145
- defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
146
- }
147
- if (example) {
148
- exampleBody = JSON.stringify(example, null, 2);
149
- }
150
- if (examples) {
151
- for (const [key, example] of Object.entries(examples)) {
152
- let body = example.value;
153
- try {
154
- // If the value is already valid JSON we shouldn't double encode the value
155
- JSON.parse(example.value);
156
- } catch (e) {
157
- body = JSON.stringify(example.value, null, 2);
158
- }
159
- examplesBodies.push({
160
- label: key,
161
- body,
162
- summary: example.summary,
163
- });
164
- }
165
- }
166
- // OpenAPI 3.1: schema.examples is an array of example values
167
- if (schemaExamples && Array.isArray(schemaExamples)) {
168
- schemaExamples.forEach((schemaExample, index) => {
169
- const body = JSON.stringify(schemaExample, null, 2);
170
- examplesBodies.push({
171
- label: `Example ${index + 1}`,
172
- body,
173
- summary: undefined,
174
- });
175
- });
176
- }
177
- language = "json";
178
- }
179
- if (contentType === "application/xml" || contentType.endsWith("+xml")) {
180
- if (jsonRequestBodyExample) {
181
- try {
182
- defaultBody = (0, xml_formatter_1.default)(
183
- (0, json2xml_1.default)(jsonRequestBodyExample, ""),
184
- {
185
- indentation: " ",
186
- lineSeparator: "\n",
187
- collapseContent: true,
188
- }
189
- );
190
- } catch {
191
- defaultBody = (0, json2xml_1.default)(jsonRequestBodyExample);
192
- }
193
- }
194
- if (example) {
195
- try {
196
- exampleBody = (0, xml_formatter_1.default)(
197
- (0, json2xml_1.default)(example, ""),
198
- {
199
- indentation: " ",
200
- lineSeparator: "\n",
201
- collapseContent: true,
202
- }
203
- );
204
- } catch {
205
- exampleBody = (0, json2xml_1.default)(example);
206
- }
207
- }
208
- if (examples) {
209
- for (const [key, example] of Object.entries(examples)) {
210
- let formattedXmlBody;
211
- try {
212
- formattedXmlBody = (0, xml_formatter_1.default)(example.value, {
213
- indentation: " ",
214
- lineSeparator: "\n",
215
- collapseContent: true,
216
- });
217
- } catch {
218
- formattedXmlBody = example.value;
219
- }
220
- examplesBodies.push({
221
- label: key,
222
- body: formattedXmlBody,
223
- summary: example.summary,
224
- });
225
- }
226
- }
227
- // OpenAPI 3.1: schema.examples is an array of example values
228
- if (schemaExamples && Array.isArray(schemaExamples)) {
229
- schemaExamples.forEach((schemaExample, index) => {
230
- let formattedXmlBody;
231
- try {
232
- formattedXmlBody = (0, xml_formatter_1.default)(
233
- (0, json2xml_1.default)(schemaExample, ""),
234
- {
235
- indentation: " ",
236
- lineSeparator: "\n",
237
- collapseContent: true,
238
- }
239
- );
240
- } catch {
241
- formattedXmlBody = (0, json2xml_1.default)(schemaExample);
242
- }
243
- examplesBodies.push({
244
- label: `Example ${index + 1}`,
245
- body: formattedXmlBody,
246
- summary: undefined,
247
- });
248
- });
249
- }
250
- language = "xml";
251
- }
252
386
  if (exampleBody) {
253
387
  return react_1.default.createElement(
254
388
  FormItem_1.default,
@@ -269,6 +403,7 @@ function Body({
269
403
  react_1.default.createElement(
270
404
  LiveEditor_1.default,
271
405
  {
406
+ key: `${contentType}-${schemaSelectionKey}`,
272
407
  action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
273
408
  language: language,
274
409
  required: required,
@@ -289,6 +424,7 @@ function Body({
289
424
  react_1.default.createElement(
290
425
  LiveEditor_1.default,
291
426
  {
427
+ key: `${contentType}-example`,
292
428
  action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
293
429
  language: language,
294
430
  required: required,
@@ -319,6 +455,7 @@ function Body({
319
455
  react_1.default.createElement(
320
456
  LiveEditor_1.default,
321
457
  {
458
+ key: `${contentType}-${schemaSelectionKey}`,
322
459
  action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
323
460
  language: language,
324
461
  required: required,
@@ -326,31 +463,28 @@ function Body({
326
463
  defaultBody
327
464
  )
328
465
  ),
329
- examplesBodies.map((example) => {
466
+ examplesBodies.map((ex) => {
330
467
  return (
331
468
  // @ts-ignore
332
469
  react_1.default.createElement(
333
470
  TabItem_1.default,
334
- {
335
- label: example.label,
336
- value: example.label,
337
- key: example.label,
338
- },
339
- example.summary &&
471
+ { label: ex.label, value: ex.label, key: ex.label },
472
+ ex.summary &&
340
473
  react_1.default.createElement(
341
474
  Markdown_1.default,
342
475
  null,
343
- example.summary
476
+ ex.summary
344
477
  ),
345
- example.body &&
478
+ ex.body &&
346
479
  react_1.default.createElement(
347
480
  LiveEditor_1.default,
348
481
  {
482
+ key: `${contentType}-${ex.label}`,
349
483
  action: (code) =>
350
484
  dispatch((0, slice_1.setStringRawBody)(code)),
351
485
  language: language,
352
486
  },
353
- example.body
487
+ ex.body
354
488
  )
355
489
  )
356
490
  );
@@ -364,6 +498,7 @@ function Body({
364
498
  react_1.default.createElement(
365
499
  LiveEditor_1.default,
366
500
  {
501
+ key: `${contentType}-${schemaSelectionKey}`,
367
502
  action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
368
503
  language: language,
369
504
  required: required,
@@ -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;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ var __importDefault =
9
+ (this && this.__importDefault) ||
10
+ function (mod) {
11
+ return mod && mod.__esModule ? mod : { default: mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.resolveSchemaWithSelections = resolveSchemaWithSelections;
15
+ const merge_1 = __importDefault(require("lodash/merge"));
16
+ /**
17
+ * Resolves a schema by replacing anyOf/oneOf with the selected option based on user selections.
18
+ *
19
+ * @param schema - The original schema object
20
+ * @param selections - Map of schema paths to selected indices
21
+ * @param basePath - The base path for this schema (used for looking up selections)
22
+ * @returns A new schema with anyOf/oneOf resolved to selected options
23
+ */
24
+ function resolveSchemaWithSelections(
25
+ schema,
26
+ selections,
27
+ basePath = "requestBody"
28
+ ) {
29
+ if (!schema) {
30
+ return schema;
31
+ }
32
+ // Deep clone to avoid mutating the original schema
33
+ const schemaCopy = JSON.parse(JSON.stringify(schema));
34
+ return resolveSchemaRecursive(schemaCopy, selections, basePath);
35
+ }
36
+ function resolveSchemaRecursive(schema, selections, currentPath) {
37
+ // Handle oneOf
38
+ if (schema.oneOf && Array.isArray(schema.oneOf)) {
39
+ const selectedIndex = selections[currentPath] ?? 0;
40
+ const selectedSchema = schema.oneOf[selectedIndex];
41
+ if (selectedSchema) {
42
+ // If there are shared properties, merge them with the selected schema
43
+ if (schema.properties) {
44
+ const mergedSchema = (0, merge_1.default)({}, schema, selectedSchema);
45
+ delete mergedSchema.oneOf;
46
+ // Continue resolving nested schemas in the merged result
47
+ return resolveSchemaRecursive(
48
+ mergedSchema,
49
+ selections,
50
+ `${currentPath}.${selectedIndex}`
51
+ );
52
+ }
53
+ // No shared properties, just use the selected schema
54
+ // Continue resolving in case there are nested anyOf/oneOf
55
+ return resolveSchemaRecursive(
56
+ selectedSchema,
57
+ selections,
58
+ `${currentPath}.${selectedIndex}`
59
+ );
60
+ }
61
+ }
62
+ // Handle anyOf
63
+ if (schema.anyOf && Array.isArray(schema.anyOf)) {
64
+ const selectedIndex = selections[currentPath] ?? 0;
65
+ const selectedSchema = schema.anyOf[selectedIndex];
66
+ if (selectedSchema) {
67
+ // If there are shared properties, merge them with the selected schema
68
+ if (schema.properties) {
69
+ const mergedSchema = (0, merge_1.default)({}, schema, selectedSchema);
70
+ delete mergedSchema.anyOf;
71
+ // Continue resolving nested schemas in the merged result
72
+ return resolveSchemaRecursive(
73
+ mergedSchema,
74
+ selections,
75
+ `${currentPath}.${selectedIndex}`
76
+ );
77
+ }
78
+ // No shared properties, just use the selected schema
79
+ // Continue resolving in case there are nested anyOf/oneOf
80
+ return resolveSchemaRecursive(
81
+ selectedSchema,
82
+ selections,
83
+ `${currentPath}.${selectedIndex}`
84
+ );
85
+ }
86
+ }
87
+ // Handle allOf - merge all schemas and continue resolving
88
+ if (schema.allOf && Array.isArray(schema.allOf)) {
89
+ // Process each allOf item, resolving any anyOf/oneOf within them
90
+ const resolvedItems = schema.allOf.map((item, index) => {
91
+ return resolveSchemaRecursive(
92
+ item,
93
+ selections,
94
+ `${currentPath}.allOf.${index}`
95
+ );
96
+ });
97
+ // Merge all resolved items
98
+ const mergedSchema = resolvedItems.reduce(
99
+ (acc, item) => (0, merge_1.default)(acc, item),
100
+ {}
101
+ );
102
+ // Preserve any top-level properties from the original schema
103
+ if (schema.properties) {
104
+ mergedSchema.properties = (0, merge_1.default)(
105
+ {},
106
+ mergedSchema.properties,
107
+ schema.properties
108
+ );
109
+ }
110
+ return mergedSchema;
111
+ }
112
+ // Handle object properties recursively
113
+ if (schema.properties) {
114
+ const resolvedProperties = {};
115
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
116
+ resolvedProperties[propName] = resolveSchemaRecursive(
117
+ propSchema,
118
+ selections,
119
+ `${currentPath}.${propName}`
120
+ );
121
+ }
122
+ schema.properties = resolvedProperties;
123
+ }
124
+ // Handle array items recursively
125
+ if (schema.items) {
126
+ schema.items = resolveSchemaRecursive(
127
+ schema.items,
128
+ selections,
129
+ `${currentPath}.items`
130
+ );
131
+ }
132
+ return schema;
133
+ }
@@ -0,0 +1,2 @@
1
+ export { default as schemaSelectionReducer, setSchemaSelection, clearSchemaSelections, } from "./slice";
2
+ export type { SchemaSelectionState } from "./slice";
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ var __importDefault =
9
+ (this && this.__importDefault) ||
10
+ function (mod) {
11
+ return mod && mod.__esModule ? mod : { default: mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.clearSchemaSelections =
15
+ exports.setSchemaSelection =
16
+ exports.schemaSelectionReducer =
17
+ void 0;
18
+ var slice_1 = require("./slice");
19
+ Object.defineProperty(exports, "schemaSelectionReducer", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return __importDefault(slice_1).default;
23
+ },
24
+ });
25
+ Object.defineProperty(exports, "setSchemaSelection", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return slice_1.setSchemaSelection;
29
+ },
30
+ });
31
+ Object.defineProperty(exports, "clearSchemaSelections", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return slice_1.clearSchemaSelections;
35
+ },
36
+ });