docusaurus-plugin-openapi-docs 3.0.0 → 3.0.2

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.
@@ -66,6 +66,7 @@ function createAnyOneOf(schema: SchemaObject): any {
66
66
  create("span", {
67
67
  className: "badge badge--info",
68
68
  children: type,
69
+ style: { marginBottom: "1rem" },
69
70
  }),
70
71
  create("SchemaTabs", {
71
72
  children: schema[type]!.map((anyOneSchema, index) => {
@@ -74,6 +75,25 @@ function createAnyOneOf(schema: SchemaObject): any {
74
75
  : `MOD${index + 1}`;
75
76
  const anyOneChildren = [];
76
77
 
78
+ if (anyOneSchema.description) {
79
+ anyOneChildren.push(
80
+ create("div", {
81
+ style: { marginTop: ".5rem", marginBottom: ".5rem" },
82
+ className: "openapi-schema__summary",
83
+ children: createDescription(anyOneSchema.description),
84
+ })
85
+ );
86
+ }
87
+
88
+ if (
89
+ anyOneSchema.type === "object" &&
90
+ !anyOneSchema.properties &&
91
+ !anyOneSchema.allOf &&
92
+ !anyOneSchema.items
93
+ ) {
94
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
95
+ }
96
+
77
97
  if (anyOneSchema.properties !== undefined) {
78
98
  anyOneChildren.push(createProperties(anyOneSchema));
79
99
  delete anyOneSchema.properties;
@@ -415,79 +435,79 @@ function createDetailsNode(
415
435
  /**
416
436
  * For handling anyOf/oneOf properties.
417
437
  */
418
- function createAnyOneOfProperty(
419
- name: string,
420
- schemaName: string,
421
- schema: SchemaObject,
422
- required: string[] | boolean,
423
- nullable: boolean | unknown
424
- ): any {
425
- return create("SchemaItem", {
426
- collapsible: true,
427
- className: "schemaItem",
428
- children: [
429
- createDetails({
430
- className: "openapi-markdown__details",
431
- children: [
432
- createDetailsSummary({
433
- children: [
434
- create("strong", { children: name }),
435
- create("span", {
436
- style: { opacity: "0.6" },
437
- children: ` ${schemaName}`,
438
- }),
439
- guard(
440
- (schema.nullable && schema.nullable === true) ||
441
- (nullable && nullable === true),
442
- () => [
443
- create("strong", {
444
- style: {
445
- fontSize: "var(--ifm-code-font-size)",
446
- color: "var(--openapi-nullable)",
447
- },
448
- children: " nullable",
449
- }),
450
- ]
451
- ),
452
- guard(
453
- Array.isArray(required)
454
- ? required.includes(name)
455
- : required === true,
456
- () => [
457
- create("strong", {
458
- style: {
459
- fontSize: "var(--ifm-code-font-size)",
460
- color: "var(--openapi-required)",
461
- },
462
- children: " required",
463
- }),
464
- ]
465
- ),
466
- ],
467
- }),
468
- create("div", {
469
- style: { marginLeft: "1rem" },
470
- children: [
471
- guard(getQualifierMessage(schema), (message) =>
472
- create("div", {
473
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
474
- children: createDescription(message),
475
- })
476
- ),
477
- guard(schema.description, (description) =>
478
- create("div", {
479
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
480
- children: createDescription(description),
481
- })
482
- ),
483
- ],
484
- }),
485
- createAnyOneOf(schema),
486
- ],
487
- }),
488
- ],
489
- });
490
- }
438
+ // function createAnyOneOfProperty(
439
+ // name: string,
440
+ // schemaName: string,
441
+ // schema: SchemaObject,
442
+ // required: string[] | boolean,
443
+ // nullable: boolean | unknown
444
+ // ): any {
445
+ // return create("SchemaItem", {
446
+ // collapsible: true,
447
+ // className: "schemaItem",
448
+ // children: [
449
+ // createDetails({
450
+ // className: "openapi-markdown__details",
451
+ // children: [
452
+ // createDetailsSummary({
453
+ // children: [
454
+ // create("strong", { children: name }),
455
+ // create("span", {
456
+ // style: { opacity: "0.6" },
457
+ // children: ` ${schemaName}`,
458
+ // }),
459
+ // guard(
460
+ // (schema.nullable && schema.nullable === true) ||
461
+ // (nullable && nullable === true),
462
+ // () => [
463
+ // create("strong", {
464
+ // style: {
465
+ // fontSize: "var(--ifm-code-font-size)",
466
+ // color: "var(--openapi-nullable)",
467
+ // },
468
+ // children: " nullable",
469
+ // }),
470
+ // ]
471
+ // ),
472
+ // guard(
473
+ // Array.isArray(required)
474
+ // ? required.includes(name)
475
+ // : required === true,
476
+ // () => [
477
+ // create("strong", {
478
+ // style: {
479
+ // fontSize: "var(--ifm-code-font-size)",
480
+ // color: "var(--openapi-required)",
481
+ // },
482
+ // children: " required",
483
+ // }),
484
+ // ]
485
+ // ),
486
+ // ],
487
+ // }),
488
+ // create("div", {
489
+ // style: { marginLeft: "1rem" },
490
+ // children: [
491
+ // guard(getQualifierMessage(schema), (message) =>
492
+ // create("div", {
493
+ // style: { marginTop: ".5rem", marginBottom: ".5rem" },
494
+ // children: createDescription(message),
495
+ // })
496
+ // ),
497
+ // guard(schema.description, (description) =>
498
+ // create("div", {
499
+ // style: { marginTop: ".5rem", marginBottom: ".5rem" },
500
+ // children: createDescription(description),
501
+ // })
502
+ // ),
503
+ // ],
504
+ // }),
505
+ // createAnyOneOf(schema),
506
+ // ],
507
+ // }),
508
+ // ],
509
+ // });
510
+ // }
491
511
 
492
512
  /**
493
513
  * For handling discriminators that map to a same-level property (like 'petType').
@@ -595,6 +615,7 @@ function createEdges({
595
615
  }
596
616
 
597
617
  const schemaName = getSchemaName(schema);
618
+
598
619
  if (discriminator !== undefined && discriminator.propertyName === name) {
599
620
  return createPropertyDiscriminator(
600
621
  name,
@@ -606,7 +627,48 @@ function createEdges({
606
627
  }
607
628
 
608
629
  if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
609
- return createAnyOneOfProperty(
630
+ return createDetailsNode(
631
+ name,
632
+ schemaName,
633
+ schema,
634
+ required,
635
+ schema.nullable
636
+ );
637
+ }
638
+
639
+ if (schema.properties !== undefined) {
640
+ return createDetailsNode(
641
+ name,
642
+ schemaName,
643
+ schema,
644
+ required,
645
+ schema.nullable
646
+ );
647
+ }
648
+
649
+ if (schema.additionalProperties !== undefined) {
650
+ return createDetailsNode(
651
+ name,
652
+ schemaName,
653
+ schema,
654
+ required,
655
+ schema.nullable
656
+ );
657
+ }
658
+
659
+ // array of objects
660
+ if (schema.items?.properties !== undefined) {
661
+ return createDetailsNode(
662
+ name,
663
+ schemaName,
664
+ schema,
665
+ required,
666
+ schema.nullable
667
+ );
668
+ }
669
+
670
+ if (schema.items?.anyOf !== undefined || schema.items?.oneOf !== undefined) {
671
+ return createDetailsNode(
610
672
  name,
611
673
  schemaName,
612
674
  schema,
@@ -687,47 +749,6 @@ function createEdges({
687
749
  });
688
750
  }
689
751
 
690
- if (schema.properties !== undefined) {
691
- return createDetailsNode(
692
- name,
693
- schemaName,
694
- schema,
695
- required,
696
- schema.nullable
697
- );
698
- }
699
-
700
- if (schema.additionalProperties !== undefined) {
701
- return createDetailsNode(
702
- name,
703
- schemaName,
704
- schema,
705
- required,
706
- schema.nullable
707
- );
708
- }
709
-
710
- // array of objects
711
- if (schema.items?.properties !== undefined) {
712
- return createDetailsNode(
713
- name,
714
- schemaName,
715
- schema,
716
- required,
717
- schema.nullable
718
- );
719
- }
720
-
721
- if (schema.items?.anyOf !== undefined || schema.items?.oneOf !== undefined) {
722
- return createDetailsNode(
723
- name,
724
- schemaName,
725
- schema,
726
- required,
727
- schema.nullable
728
- );
729
- }
730
-
731
752
  // primitives and array of non-objects
732
753
  return create("SchemaItem", {
733
754
  collapsible: false,
@@ -767,6 +788,19 @@ export function createNodes(
767
788
  nodes.push(createAnyOneOf(schema));
768
789
  }
769
790
 
791
+ if (schema.properties !== undefined) {
792
+ nodes.push(createProperties(schema));
793
+ }
794
+
795
+ if (schema.additionalProperties !== undefined) {
796
+ nodes.push(createAdditionalProperties(schema));
797
+ }
798
+
799
+ // TODO: figure out how to handle array of objects
800
+ if (schema.items !== undefined) {
801
+ nodes.push(createItems(schema));
802
+ }
803
+
770
804
  if (schema.allOf !== undefined) {
771
805
  const { mergedSchemas } = mergeAllOf(schema.allOf);
772
806
 
@@ -782,19 +816,6 @@ export function createNodes(
782
816
  }
783
817
  }
784
818
 
785
- if (schema.properties !== undefined) {
786
- nodes.push(createProperties(schema));
787
- }
788
-
789
- if (schema.additionalProperties !== undefined) {
790
- nodes.push(createAdditionalProperties(schema));
791
- }
792
-
793
- // TODO: figure out how to handle array of objects
794
- if (schema.items !== undefined) {
795
- nodes.push(createItems(schema));
796
- }
797
-
798
819
  if (nodes.length && nodes.length > 0) {
799
820
  return nodes.filter(Boolean).flat();
800
821
  }
@@ -127,8 +127,9 @@ export function createResponseExamples(
127
127
  value: `${exampleName}`,
128
128
  children: [
129
129
  guard(exampleValue.summary, (summary) => [
130
- create("Markdown", {
131
- children: ` ${summary}`,
130
+ create("div", {
131
+ children: `${summary}`,
132
+ className: "openapi-example__summary",
132
133
  }),
133
134
  ]),
134
135
  create("ResponseSamples", {
@@ -143,8 +144,9 @@ export function createResponseExamples(
143
144
  value: `${exampleName}`,
144
145
  children: [
145
146
  guard(exampleValue.summary, (summary) => [
146
- create("Markdown", {
147
- children: ` ${summary}`,
147
+ create("div", {
148
+ children: `${summary}`,
149
+ className: "openapi-example__summary",
148
150
  }),
149
151
  ]),
150
152
  create("ResponseSamples", {
@@ -171,8 +173,9 @@ export function createResponseExample(responseExample: any, mimeType: string) {
171
173
  value: `Example`,
172
174
  children: [
173
175
  guard(responseExample.summary, (summary) => [
174
- create("Markdown", {
175
- children: ` ${summary}`,
176
+ create("div", {
177
+ children: `${summary}`,
178
+ className: "openapi-example__summary",
176
179
  }),
177
180
  ]),
178
181
  create("ResponseSamples", {
@@ -187,8 +190,9 @@ export function createResponseExample(responseExample: any, mimeType: string) {
187
190
  value: `Example`,
188
191
  children: [
189
192
  guard(responseExample.summary, (summary) => [
190
- create("Markdown", {
191
- children: ` ${summary}`,
193
+ create("div", {
194
+ children: `${summary}`,
195
+ className: "openapi-example__summary",
192
196
  }),
193
197
  ]),
194
198
  create("ResponseSamples", {
@@ -76,7 +76,6 @@ export function createApiPageMD({
76
76
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
77
77
  `import SchemaItem from "@theme/SchemaItem";\n`,
78
78
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
79
- `import Markdown from "@theme/Markdown";\n`,
80
79
  `import Heading from "@theme/Heading";\n`,
81
80
  `import OperationTabs from "@theme/OperationTabs";\n`,
82
81
  `import TabItem from "@theme/TabItem";\n\n`,
@@ -30,8 +30,8 @@ const primitives: Primitives = {
30
30
  string: {
31
31
  default: () => "string",
32
32
  email: () => "user@example.com",
33
- date: () => new Date().toISOString().substring(0, 10),
34
- "date-time": () => new Date().toISOString(),
33
+ date: () => "2024-07-29",
34
+ "date-time": () => "2024-07-29T15:51:28.071Z",
35
35
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
36
36
  hostname: () => "example.com",
37
37
  ipv4: () => "198.51.100.42",
@@ -30,8 +30,8 @@ const primitives: Primitives = {
30
30
  string: {
31
31
  default: () => "string",
32
32
  email: () => "user@example.com",
33
- date: () => new Date().toISOString().substring(0, 10),
34
- "date-time": () => new Date().toISOString(),
33
+ date: () => "2024-07-29",
34
+ "date-time": () => "2024-07-29T15:51:28.071Z",
35
35
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
36
36
  hostname: () => "example.com",
37
37
  ipv4: () => "198.51.100.42",