docusaurus-plugin-openapi-docs 0.0.0-613 → 0.0.0-616

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.
@@ -5,902 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { MediaTypeObject, SchemaObject } from "../openapi/types";
9
- import {
10
- createClosingArrayBracket,
11
- createOpeningArrayBracket,
12
- } from "./createArrayBracket";
8
+ import { MediaTypeObject } from "../openapi/types";
13
9
  import { createDescription } from "./createDescription";
14
10
  import { createDetails } from "./createDetails";
15
11
  import { createDetailsSummary } from "./createDetailsSummary";
16
- import { getQualifierMessage, getSchemaName } from "./schema";
12
+ import { createNodes } from "./createSchema";
17
13
  import { create, guard } from "./utils";
18
14
 
19
- const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
20
-
21
- /**
22
- * Returns a merged representation of allOf array of schemas.
23
- */
24
- export function mergeAllOf(allOf: SchemaObject[]) {
25
- const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
26
- resolvers: {
27
- readOnly: function () {
28
- return true;
29
- },
30
- example: function () {
31
- return true;
32
- },
33
- "x-examples": function () {
34
- return true;
35
- },
36
- },
37
- ignoreAdditionalProperties: true,
38
- });
39
-
40
- const required = allOf.reduce((acc, cur) => {
41
- if (Array.isArray(cur.required)) {
42
- const next = [...acc, ...cur.required];
43
- return next;
44
- }
45
- return acc;
46
- }, [] as any);
47
-
48
- return { mergedSchemas, required };
49
- }
50
-
51
- /**
52
- * For handling nested anyOf/oneOf.
53
- */
54
- function createAnyOneOf(schema: SchemaObject): any {
55
- const type = schema.oneOf ? "oneOf" : "anyOf";
56
- return create("div", {
57
- children: [
58
- create("span", {
59
- className: "badge badge--info",
60
- children: type,
61
- }),
62
- create("SchemaTabs", {
63
- children: schema[type]!.map((anyOneSchema, index) => {
64
- const label = anyOneSchema.title
65
- ? anyOneSchema.title
66
- : `MOD${index + 1}`;
67
- const anyOneChildren = [];
68
-
69
- if (anyOneSchema.properties !== undefined) {
70
- anyOneChildren.push(createProperties(anyOneSchema));
71
- delete anyOneSchema.properties;
72
- }
73
-
74
- if (anyOneSchema.allOf !== undefined) {
75
- anyOneChildren.push(createNodes(anyOneSchema));
76
- delete anyOneSchema.allOf;
77
- }
78
-
79
- if (anyOneSchema.items !== undefined) {
80
- anyOneChildren.push(createItems(anyOneSchema));
81
- delete anyOneSchema.items;
82
- }
83
-
84
- if (
85
- anyOneSchema.type === "string" ||
86
- anyOneSchema.type === "number" ||
87
- anyOneSchema.type === "integer" ||
88
- anyOneSchema.type === "boolean"
89
- ) {
90
- anyOneChildren.push(createNodes(anyOneSchema));
91
- }
92
- if (anyOneChildren.length) {
93
- if (schema.type === "array") {
94
- return create("TabItem", {
95
- label: label,
96
- value: `${index}-item-properties`,
97
- children: [
98
- createOpeningArrayBracket(),
99
- anyOneChildren,
100
- createClosingArrayBracket(),
101
- ]
102
- .filter(Boolean)
103
- .flat(),
104
- });
105
- }
106
- return create("TabItem", {
107
- label: label,
108
- value: `${index}-item-properties`,
109
- children: anyOneChildren.filter(Boolean).flat(),
110
- });
111
- }
112
-
113
- return undefined;
114
- }),
115
- }),
116
- ],
117
- });
118
- }
119
-
120
- function createProperties(schema: SchemaObject) {
121
- const discriminator = schema.discriminator;
122
- return Object.entries(schema.properties!).map(([key, val]) => {
123
- return createEdges({
124
- name: key,
125
- schema: val,
126
- required: Array.isArray(schema.required)
127
- ? schema.required.includes(key)
128
- : false,
129
- discriminator,
130
- });
131
- });
132
- }
133
-
134
- function createAdditionalProperties(schema: SchemaObject) {
135
- // TODO?:
136
- // {
137
- // description: 'Integration configuration. See \n' +
138
- // '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
139
- // example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
140
- // externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
141
- // type: 'object'
142
- // }
143
-
144
- // TODO?:
145
- // {
146
- // items: {
147
- // properties: {
148
- // aliasField: [Object],
149
- // displayName: [Object],
150
- // fieldName: [Object],
151
- // maxLength: [Object],
152
- // options: [Object],
153
- // redlockMapping: [Object],
154
- // required: [Object],
155
- // type: [Object],
156
- // typeaheadUri: [Object],
157
- // value: [Object]
158
- // },
159
- // type: 'object'
160
- // },
161
- // type: 'array'
162
- // }
163
- const additionalProperties = schema.additionalProperties;
164
- const type: string | unknown = additionalProperties?.type;
165
- // Handle free-form objects
166
- if (String(additionalProperties) === "true" && schema.type === "object") {
167
- return create("SchemaItem", {
168
- name: "property name*",
169
- required: false,
170
- schemaName: "any",
171
- qualifierMessage: getQualifierMessage(schema.additionalProperties),
172
- schema: schema,
173
- collapsible: false,
174
- discriminator: false,
175
- });
176
- }
177
- if (
178
- (type === "object" || type === "array") &&
179
- (additionalProperties?.properties ||
180
- additionalProperties?.items ||
181
- additionalProperties?.allOf ||
182
- additionalProperties?.additionalProperties ||
183
- additionalProperties?.oneOf ||
184
- additionalProperties?.anyOf)
185
- ) {
186
- const title = additionalProperties.title as string;
187
- const schemaName = getSchemaName(additionalProperties);
188
- const required = schema.required ?? false;
189
- return createDetailsNode(
190
- "property name*",
191
- title ?? schemaName,
192
- additionalProperties,
193
- required,
194
- schema.nullable
195
- );
196
- }
197
-
198
- if (
199
- (schema.additionalProperties?.type as string) === "string" ||
200
- (schema.additionalProperties?.type as string) === "object" ||
201
- (schema.additionalProperties?.type as string) === "boolean" ||
202
- (schema.additionalProperties?.type as string) === "integer" ||
203
- (schema.additionalProperties?.type as string) === "number"
204
- ) {
205
- const additionalProperties =
206
- schema.additionalProperties?.additionalProperties;
207
- if (additionalProperties !== undefined) {
208
- const type = schema.additionalProperties?.additionalProperties?.type;
209
- const schemaName = getSchemaName(
210
- schema.additionalProperties?.additionalProperties!
211
- );
212
- return create("SchemaItem", {
213
- name: "property name*",
214
- required: false,
215
- schemaName: schemaName ?? type,
216
- qualifierMessage:
217
- schema.additionalProperties ??
218
- getQualifierMessage(schema.additionalProperties),
219
- schema: schema,
220
- collapsible: false,
221
- discriminator: false,
222
- });
223
- }
224
- const schemaName = getSchemaName(schema.additionalProperties!);
225
- return create("SchemaItem", {
226
- name: "property name*",
227
- required: false,
228
- schemaName: schemaName,
229
- qualifierMessage: getQualifierMessage(schema),
230
- schema: schema.additionalProperties,
231
- collapsible: false,
232
- discriminator: false,
233
- });
234
- }
235
- return Object.entries(schema.additionalProperties!).map(([key, val]) =>
236
- createEdges({
237
- name: key,
238
- schema: val,
239
- required: Array.isArray(schema.required)
240
- ? schema.required.includes(key)
241
- : false,
242
- })
243
- );
244
- }
245
-
246
- // TODO: figure out how to handle array of objects
247
- function createItems(schema: SchemaObject) {
248
- if (schema.items?.properties !== undefined) {
249
- return [
250
- createOpeningArrayBracket(),
251
- createProperties(schema.items),
252
- createClosingArrayBracket(),
253
- ].flat();
254
- }
255
-
256
- if (schema.items?.additionalProperties !== undefined) {
257
- return [
258
- createOpeningArrayBracket(),
259
- createAdditionalProperties(schema.items),
260
- createClosingArrayBracket(),
261
- ].flat();
262
- }
263
-
264
- if (schema.items?.oneOf !== undefined || schema.items?.anyOf !== undefined) {
265
- return [
266
- createOpeningArrayBracket(),
267
- createAnyOneOf(schema.items!),
268
- createClosingArrayBracket(),
269
- ].flat();
270
- }
271
-
272
- if (schema.items?.allOf !== undefined) {
273
- // TODO: figure out if and how we should pass merged required array
274
- const {
275
- mergedSchemas,
276
- }: { mergedSchemas: SchemaObject; required: string[] } = mergeAllOf(
277
- schema.items?.allOf
278
- );
279
-
280
- // Handles combo anyOf/oneOf + properties
281
- if (
282
- (mergedSchemas.oneOf !== undefined ||
283
- mergedSchemas.anyOf !== undefined) &&
284
- mergedSchemas.properties
285
- ) {
286
- return [
287
- createOpeningArrayBracket(),
288
- createAnyOneOf(mergedSchemas),
289
- createProperties(mergedSchemas),
290
- createClosingArrayBracket(),
291
- ].flat();
292
- }
293
-
294
- // Handles only anyOf/oneOf
295
- if (
296
- mergedSchemas.oneOf !== undefined ||
297
- mergedSchemas.anyOf !== undefined
298
- ) {
299
- return [
300
- createOpeningArrayBracket(),
301
- createAnyOneOf(mergedSchemas),
302
- createClosingArrayBracket(),
303
- ].flat();
304
- }
305
-
306
- // Handles properties
307
- if (mergedSchemas.properties !== undefined) {
308
- return [
309
- createOpeningArrayBracket(),
310
- createProperties(mergedSchemas),
311
- createClosingArrayBracket(),
312
- ].flat();
313
- }
314
- }
315
-
316
- if (
317
- schema.items?.type === "string" ||
318
- schema.items?.type === "number" ||
319
- schema.items?.type === "integer" ||
320
- schema.items?.type === "boolean" ||
321
- schema.items?.type === "object"
322
- ) {
323
- return [
324
- createOpeningArrayBracket(),
325
- createNodes(schema.items),
326
- createClosingArrayBracket(),
327
- ].flat();
328
- }
329
-
330
- // TODO: clean this up or eliminate it?
331
- return [
332
- createOpeningArrayBracket(),
333
- Object.entries(schema.items!).map(([key, val]) =>
334
- createEdges({
335
- name: key,
336
- schema: val,
337
- required: Array.isArray(schema.required)
338
- ? schema.required.includes(key)
339
- : false,
340
- })
341
- ),
342
- createClosingArrayBracket(),
343
- ].flat();
344
- }
345
-
346
- /**
347
- * For handling discriminators that do not map to a same-level property
348
- */
349
- // function createDiscriminator(schema: SchemaObject) {
350
- // const discriminator = schema.discriminator;
351
- // const propertyName = discriminator?.propertyName;
352
- // const propertyType = "string"; // should always be string
353
- // const mapping: any = discriminator?.mapping;
354
-
355
- // // Explicit mapping is required since we can't support implicit
356
- // if (mapping === undefined) {
357
- // return undefined;
358
- // }
359
-
360
- // // Attempt to get the property description we want to display
361
- // // TODO: how to make it predictable when handling allOf
362
- // let propertyDescription;
363
- // const firstMappingSchema = mapping[Object.keys(mapping)[0]];
364
- // if (firstMappingSchema.properties !== undefined) {
365
- // propertyDescription =
366
- // firstMappingSchema.properties![propertyName!].description;
367
- // }
368
- // if (firstMappingSchema.allOf !== undefined) {
369
- // const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
370
- // firstMappingSchema.allOf
371
- // );
372
- // if (mergedSchemas.properties !== undefined) {
373
- // propertyDescription =
374
- // mergedSchemas.properties[propertyName!]?.description;
375
- // }
376
- // }
377
-
378
- // if (propertyDescription === undefined) {
379
- // if (
380
- // schema.properties !== undefined &&
381
- // schema.properties![propertyName!] !== undefined
382
- // ) {
383
- // propertyDescription = schema.properties![propertyName!].description;
384
- // }
385
- // }
386
-
387
- // return create("div", {
388
- // className: "discriminatorItem",
389
- // children: create("div", {
390
- // children: [
391
- // create("strong", {
392
- // style: { paddingLeft: "1rem" },
393
- // children: propertyName,
394
- // }),
395
- // guard(propertyType, (name) =>
396
- // create("span", {
397
- // style: { opacity: "0.6" },
398
- // children: ` ${propertyType}`,
399
- // })
400
- // ),
401
- // guard(getQualifierMessage(schema.discriminator as any), (message) =>
402
- // create("div", {
403
- // style: {
404
- // paddingLeft: "1rem",
405
- // },
406
- // children: createDescription(message),
407
- // })
408
- // ),
409
- // guard(propertyDescription, (description) =>
410
- // create("div", {
411
- // style: {
412
- // paddingLeft: "1rem",
413
- // },
414
- // children: createDescription(description),
415
- // })
416
- // ),
417
- // create("DiscriminatorTabs", {
418
- // children: Object.keys(mapping!).map((key, index) => {
419
- // if (mapping[key].allOf !== undefined) {
420
- // const { mergedSchemas }: { mergedSchemas: SchemaObject } =
421
- // mergeAllOf(mapping[key].allOf);
422
- // // Cleanup duplicate property from mapping schema
423
- // delete mergedSchemas.properties![propertyName!];
424
- // mapping[key] = mergedSchemas;
425
- // }
426
-
427
- // if (mapping[key].properties !== undefined) {
428
- // // Cleanup duplicate property from mapping schema
429
- // delete mapping[key].properties![propertyName!];
430
- // }
431
-
432
- // const label = key;
433
- // return create("TabItem", {
434
- // label: label,
435
- // value: `${index}-item-discriminator`,
436
- // children: [
437
- // create("div", {
438
- // style: { marginLeft: "-4px" },
439
- // children: createNodes(mapping[key]),
440
- // }),
441
- // ],
442
- // });
443
- // }),
444
- // }),
445
- // ],
446
- // }),
447
- // });
448
- // }
449
-
450
- function createDetailsNode(
451
- name: string,
452
- schemaName: string,
453
- schema: SchemaObject,
454
- required: string[] | boolean,
455
- nullable: boolean | unknown
456
- ): any {
457
- return create("SchemaItem", {
458
- collapsible: true,
459
- className: "schemaItem",
460
- children: [
461
- createDetails({
462
- children: [
463
- createDetailsSummary({
464
- children: [
465
- create("strong", { children: name }),
466
- create("span", {
467
- style: { opacity: "0.6" },
468
- children: ` ${schemaName}`,
469
- }),
470
- guard(
471
- (schema.nullable && schema.nullable === true) ||
472
- (nullable && nullable === true),
473
- () => [
474
- create("strong", {
475
- style: {
476
- fontSize: "var(--ifm-code-font-size)",
477
- color: "var(--openapi-nullable)",
478
- },
479
- children: " nullable",
480
- }),
481
- ]
482
- ),
483
- guard(
484
- Array.isArray(required)
485
- ? required.includes(name)
486
- : required === true,
487
- () => [
488
- create("strong", {
489
- style: {
490
- fontSize: "var(--ifm-code-font-size)",
491
- color: "var(--openapi-required)",
492
- },
493
- children: " required",
494
- }),
495
- ]
496
- ),
497
- ],
498
- }),
499
- create("div", {
500
- style: { marginLeft: "1rem" },
501
- children: [
502
- guard(getQualifierMessage(schema), (message) =>
503
- create("div", {
504
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
505
- children: createDescription(message),
506
- })
507
- ),
508
- guard(schema.description, (description) =>
509
- create("div", {
510
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
511
- children: createDescription(description),
512
- })
513
- ),
514
- createNodes(schema),
515
- ],
516
- }),
517
- ],
518
- }),
519
- ],
520
- });
521
- }
522
-
523
- function createOneOfProperty(
524
- name: string,
525
- schemaName: string,
526
- schema: SchemaObject,
527
- required: string[] | boolean,
528
- nullable: boolean | unknown
529
- ): any {
530
- return create("SchemaItem", {
531
- collapsible: true,
532
- className: "schemaItem",
533
- children: [
534
- createDetails({
535
- children: [
536
- createDetailsSummary({
537
- children: [
538
- create("strong", { children: name }),
539
- create("span", {
540
- style: { opacity: "0.6" },
541
- children: ` ${schemaName}`,
542
- }),
543
- guard(
544
- (schema.nullable && schema.nullable === true) ||
545
- (nullable && nullable === true),
546
- () => [
547
- create("strong", {
548
- style: {
549
- fontSize: "var(--ifm-code-font-size)",
550
- color: "var(--openapi-nullable)",
551
- },
552
- children: " nullable",
553
- }),
554
- ]
555
- ),
556
- guard(
557
- Array.isArray(required)
558
- ? required.includes(name)
559
- : required === true,
560
- () => [
561
- create("strong", {
562
- style: {
563
- fontSize: "var(--ifm-code-font-size)",
564
- color: "var(--openapi-required)",
565
- },
566
- children: " required",
567
- }),
568
- ]
569
- ),
570
- ],
571
- }),
572
- create("div", {
573
- style: { marginLeft: "1rem" },
574
- children: [
575
- guard(getQualifierMessage(schema), (message) =>
576
- create("div", {
577
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
578
- children: createDescription(message),
579
- })
580
- ),
581
- guard(schema.description, (description) =>
582
- create("div", {
583
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
584
- children: createDescription(description),
585
- })
586
- ),
587
- ],
588
- }),
589
- create("div", {
590
- children: [
591
- create("span", {
592
- className: "badge badge--info",
593
- children: "oneOf",
594
- }),
595
- create("SchemaTabs", {
596
- children: schema["oneOf"]!.map((property, index) => {
597
- const label = property.type ?? `MOD${index + 1}`;
598
- return create("TabItem", {
599
- label: label,
600
- value: `${index}-property`,
601
- children: [
602
- create("p", { children: label }),
603
- guard(schema.description, (description) =>
604
- create("div", {
605
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
606
- children: createDescription(description),
607
- })
608
- ),
609
- ],
610
- });
611
- }),
612
- }),
613
- ],
614
- }),
615
- ],
616
- }),
617
- ],
618
- });
619
- }
620
-
621
- /**
622
- * For handling discriminators that map to a same-level property (like 'petType').
623
- * Note: These should only be encountered while iterating through properties.
624
- */
625
- function createPropertyDiscriminator(
626
- name: string,
627
- schemaName: string,
628
- schema: SchemaObject,
629
- discriminator: any,
630
- required: string[] | boolean
631
- ) {
632
- if (schema === undefined) {
633
- return undefined;
634
- }
635
-
636
- if (discriminator.mapping === undefined) {
637
- return undefined;
638
- }
639
-
640
- return create("SchemaItem", {
641
- name,
642
- required: Array.isArray(required) ? required.includes(name) : required,
643
- schemaName: schemaName,
644
- qualifierMessage: getQualifierMessage(schema),
645
- schema: schema,
646
- collapsible: false,
647
- discriminator: true,
648
- children: [
649
- create("DiscriminatorTabs", {
650
- children: Object.keys(discriminator?.mapping!).map((key, index) => {
651
- const label = key;
652
- return create("TabItem", {
653
- label: label,
654
- value: `${index}-item-discriminator`,
655
- children: createNodes(discriminator?.mapping[key]),
656
- });
657
- }),
658
- }),
659
- ],
660
- });
661
- }
662
-
663
- interface EdgeProps {
664
- name: string;
665
- schema: SchemaObject;
666
- required: string[] | boolean;
667
- discriminator?: any | unknown;
668
- }
669
-
670
- /**
671
- * Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
672
- */
673
- function createEdges({
674
- name,
675
- schema,
676
- required,
677
- discriminator,
678
- }: EdgeProps): any {
679
- const schemaName = getSchemaName(schema);
680
-
681
- if (discriminator !== undefined && discriminator.propertyName === name) {
682
- return createPropertyDiscriminator(
683
- name,
684
- "string",
685
- schema,
686
- discriminator,
687
- required
688
- );
689
- }
690
-
691
- if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
692
- return createOneOfProperty(
693
- name,
694
- schemaName,
695
- schema,
696
- required,
697
- schema.nullable
698
- );
699
- }
700
-
701
- if (schema.allOf !== undefined) {
702
- const {
703
- mergedSchemas,
704
- required,
705
- }: { mergedSchemas: SchemaObject; required: string[] | boolean } =
706
- mergeAllOf(schema.allOf);
707
- const mergedSchemaName = getSchemaName(mergedSchemas);
708
-
709
- if (
710
- mergedSchemas.oneOf !== undefined ||
711
- mergedSchemas.anyOf !== undefined
712
- ) {
713
- return createDetailsNode(
714
- name,
715
- mergedSchemaName,
716
- mergedSchemas,
717
- required,
718
- schema.nullable
719
- );
720
- }
721
-
722
- if (mergedSchemas.properties !== undefined) {
723
- return createDetailsNode(
724
- name,
725
- mergedSchemaName,
726
- mergedSchemas,
727
- required,
728
- schema.nullable
729
- );
730
- }
731
-
732
- if (mergedSchemas.additionalProperties !== undefined) {
733
- return createDetailsNode(
734
- name,
735
- mergedSchemaName,
736
- mergedSchemas,
737
- required,
738
- schema.nullable
739
- );
740
- }
741
-
742
- // array of objects
743
- if (mergedSchemas.items?.properties !== undefined) {
744
- return createDetailsNode(
745
- name,
746
- mergedSchemaName,
747
- mergedSchemas,
748
- required,
749
- schema.nullable
750
- );
751
- }
752
-
753
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
754
- return undefined;
755
- }
756
-
757
- return create("SchemaItem", {
758
- collapsible: false,
759
- name,
760
- required: Array.isArray(required) ? required.includes(name) : required,
761
- schemaName: schemaName,
762
- qualifierMessage: getQualifierMessage(schema),
763
- schema: mergedSchemas,
764
- });
765
- }
766
-
767
- if (schema.properties !== undefined) {
768
- return createDetailsNode(
769
- name,
770
- schemaName,
771
- schema,
772
- required,
773
- schema.nullable
774
- );
775
- }
776
-
777
- if (schema.additionalProperties !== undefined) {
778
- return createDetailsNode(
779
- name,
780
- schemaName,
781
- schema,
782
- required,
783
- schema.nullable
784
- );
785
- }
786
-
787
- // array of objects
788
- if (schema.items?.properties !== undefined) {
789
- return createDetailsNode(
790
- name,
791
- schemaName,
792
- schema,
793
- required,
794
- schema.nullable
795
- );
796
- }
797
-
798
- if (schema.items?.anyOf !== undefined || schema.items?.oneOf !== undefined) {
799
- return createDetailsNode(
800
- name,
801
- schemaName,
802
- schema,
803
- required,
804
- schema.nullable
805
- );
806
- }
807
-
808
- if (schema.readOnly && schema.readOnly === true) {
809
- return undefined;
810
- }
811
-
812
- // primitives and array of non-objects
813
- return create("SchemaItem", {
814
- collapsible: false,
815
- name,
816
- required: Array.isArray(required) ? required.includes(name) : required,
817
- schemaName: schemaName,
818
- qualifierMessage: getQualifierMessage(schema),
819
- schema: schema,
820
- });
821
- }
822
-
823
- /**
824
- * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
825
- */
826
- function createNodes(schema: SchemaObject): any {
827
- const nodes = [];
828
- // if (schema.discriminator !== undefined) {
829
- // return createDiscriminator(schema);
830
- // }
831
-
832
- if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
833
- nodes.push(createAnyOneOf(schema));
834
- }
835
-
836
- if (schema.allOf !== undefined) {
837
- const { mergedSchemas } = mergeAllOf(schema.allOf);
838
-
839
- // allOf seems to always result in properties
840
- if (mergedSchemas.properties !== undefined) {
841
- nodes.push(createProperties(mergedSchemas));
842
- }
843
- }
844
-
845
- if (schema.properties !== undefined) {
846
- nodes.push(createProperties(schema));
847
- }
848
-
849
- if (schema.additionalProperties !== undefined) {
850
- nodes.push(createAdditionalProperties(schema));
851
- }
852
-
853
- // TODO: figure out how to handle array of objects
854
- if (schema.items !== undefined) {
855
- nodes.push(createItems(schema));
856
- }
857
-
858
- if (nodes.length && nodes.length > 0) {
859
- return nodes.filter(Boolean).flat();
860
- }
861
-
862
- // primitive
863
- if (schema.type !== undefined) {
864
- if (schema.allOf) {
865
- //handle circular result in allOf
866
- if (schema.allOf.length && typeof schema.allOf[0] === "string") {
867
- return create("div", {
868
- style: {
869
- marginTop: ".5rem",
870
- marginBottom: ".5rem",
871
- marginLeft: "1rem",
872
- },
873
- children: createDescription(schema.allOf[0]),
874
- });
875
- }
876
- }
877
- return create("div", {
878
- style: {
879
- marginTop: ".5rem",
880
- marginBottom: ".5rem",
881
- marginLeft: "1rem",
882
- },
883
- children: createDescription(schema.type),
884
- });
885
- }
886
-
887
- // handle circular references
888
- if (typeof schema === "string") {
889
- return create("div", {
890
- style: {
891
- marginTop: ".5rem",
892
- marginBottom: ".5rem",
893
- marginLeft: "1rem",
894
- },
895
- children: [createDescription(schema)],
896
- });
897
- }
898
-
899
- // Unknown node/schema type should return undefined
900
- // So far, haven't seen this hit in testing
901
- return "any";
902
- }
903
-
904
15
  interface Props {
905
16
  style?: any;
906
17
  title: string;