docusaurus-plugin-openapi-docs 1.7.2 → 1.7.3

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.
@@ -58,7 +58,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
58
58
  */
59
59
  function createAnyOneOf(schema: SchemaObject): any {
60
60
  const type = schema.oneOf ? "oneOf" : "anyOf";
61
- return create("li", {
61
+ return create("div", {
62
62
  children: [
63
63
  create("span", {
64
64
  className: "badge badge--info",
@@ -73,14 +73,17 @@ function createAnyOneOf(schema: SchemaObject): any {
73
73
 
74
74
  if (anyOneSchema.properties !== undefined) {
75
75
  anyOneChildren.push(createProperties(anyOneSchema));
76
+ delete anyOneSchema.properties;
76
77
  }
77
78
 
78
79
  if (anyOneSchema.allOf !== undefined) {
79
80
  anyOneChildren.push(createNodes(anyOneSchema));
81
+ delete anyOneSchema.allOf;
80
82
  }
81
83
 
82
84
  if (anyOneSchema.items !== undefined) {
83
85
  anyOneChildren.push(createItems(anyOneSchema));
86
+ delete anyOneSchema.items;
84
87
  }
85
88
 
86
89
  if (
@@ -165,6 +168,18 @@ function createAdditionalProperties(schema: SchemaObject) {
165
168
  // }
166
169
  const additionalProperties = schema.additionalProperties;
167
170
  const type: string | unknown = additionalProperties?.type;
171
+ // Handle free-form objects
172
+ if (String(additionalProperties) === "true" && schema.type === "object") {
173
+ return create("SchemaItem", {
174
+ name: "property name*",
175
+ required: false,
176
+ schemaName: "any",
177
+ qualifierMessage: getQualifierMessage(schema.additionalProperties),
178
+ schema: schema,
179
+ collapsible: false,
180
+ discriminator: false,
181
+ });
182
+ }
168
183
  if (
169
184
  (type === "object" || type === "array") &&
170
185
  (additionalProperties?.properties ||
@@ -174,12 +189,12 @@ function createAdditionalProperties(schema: SchemaObject) {
174
189
  additionalProperties?.oneOf ||
175
190
  additionalProperties?.anyOf)
176
191
  ) {
177
- const title = additionalProperties.title;
178
- const schemaName = title ? `object (${title})` : "object";
192
+ const title = additionalProperties.title as string;
193
+ const schemaName = getSchemaName(additionalProperties);
179
194
  const required = schema.required ?? false;
180
195
  return createDetailsNode(
181
196
  "property name*",
182
- schemaName,
197
+ title ?? schemaName,
183
198
  additionalProperties,
184
199
  required,
185
200
  schema.nullable
@@ -197,51 +212,30 @@ function createAdditionalProperties(schema: SchemaObject) {
197
212
  schema.additionalProperties?.additionalProperties;
198
213
  if (additionalProperties !== undefined) {
199
214
  const type = schema.additionalProperties?.additionalProperties?.type;
200
- const format = schema.additionalProperties?.additionalProperties?.format;
201
- return create("li", {
202
- children: create("div", {
203
- children: [
204
- create("code", { children: `property name*` }),
205
- guard(type, (type) =>
206
- create("span", {
207
- style: { opacity: "0.6" },
208
- children: ` ${type}`,
209
- })
210
- ),
211
- guard(format, (format) =>
212
- create("span", {
213
- style: { opacity: "0.6" },
214
- children: ` (${format})`,
215
- })
216
- ),
217
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
218
- create("div", {
219
- style: { marginTop: "var(--ifm-table-cell-padding)" },
220
- children: createDescription(message),
221
- })
222
- ),
223
- ],
224
- }),
215
+ const schemaName = getSchemaName(
216
+ schema.additionalProperties?.additionalProperties!
217
+ );
218
+ return create("SchemaItem", {
219
+ name: "property name*",
220
+ required: false,
221
+ schemaName: schemaName ?? type,
222
+ qualifierMessage:
223
+ schema.additionalProperties ??
224
+ getQualifierMessage(schema.additionalProperties),
225
+ schema: schema,
226
+ collapsible: false,
227
+ discriminator: false,
225
228
  });
226
229
  }
227
- return create("li", {
228
- children: create("div", {
229
- children: [
230
- create("code", { children: `property name*` }),
231
- guard(type, (type) =>
232
- create("span", {
233
- style: { opacity: "0.6" },
234
- children: ` ${type}`,
235
- })
236
- ),
237
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
238
- create("div", {
239
- style: { marginTop: "var(--ifm-table-cell-padding)" },
240
- children: createDescription(message),
241
- })
242
- ),
243
- ],
244
- }),
230
+ const schemaName = getSchemaName(schema.additionalProperties!);
231
+ return create("SchemaItem", {
232
+ name: "property name*",
233
+ required: false,
234
+ schemaName: schemaName,
235
+ qualifierMessage: getQualifierMessage(schema),
236
+ schema: schema.additionalProperties,
237
+ collapsible: false,
238
+ discriminator: false,
245
239
  });
246
240
  }
247
241
  return Object.entries(schema.additionalProperties!).map(([key, val]) =>
@@ -532,6 +526,104 @@ function createDetailsNode(
532
526
  });
533
527
  }
534
528
 
529
+ function createOneOfProperty(
530
+ name: string,
531
+ schemaName: string,
532
+ schema: SchemaObject,
533
+ required: string[] | boolean,
534
+ nullable: boolean | unknown
535
+ ): any {
536
+ return create("SchemaItem", {
537
+ collapsible: true,
538
+ className: "schemaItem",
539
+ children: [
540
+ createDetails({
541
+ children: [
542
+ createDetailsSummary({
543
+ children: [
544
+ create("strong", { children: name }),
545
+ create("span", {
546
+ style: { opacity: "0.6" },
547
+ children: ` ${schemaName}`,
548
+ }),
549
+ guard(
550
+ (schema.nullable && schema.nullable === true) ||
551
+ (nullable && nullable === true),
552
+ () => [
553
+ create("strong", {
554
+ style: {
555
+ fontSize: "var(--ifm-code-font-size)",
556
+ color: "var(--openapi-nullable)",
557
+ },
558
+ children: " nullable",
559
+ }),
560
+ ]
561
+ ),
562
+ guard(
563
+ Array.isArray(required)
564
+ ? required.includes(name)
565
+ : required === true,
566
+ () => [
567
+ create("strong", {
568
+ style: {
569
+ fontSize: "var(--ifm-code-font-size)",
570
+ color: "var(--openapi-required)",
571
+ },
572
+ children: " required",
573
+ }),
574
+ ]
575
+ ),
576
+ ],
577
+ }),
578
+ create("div", {
579
+ style: { marginLeft: "1rem" },
580
+ children: [
581
+ guard(getQualifierMessage(schema), (message) =>
582
+ create("div", {
583
+ style: { marginTop: ".5rem", marginBottom: ".5rem" },
584
+ children: createDescription(message),
585
+ })
586
+ ),
587
+ guard(schema.description, (description) =>
588
+ create("div", {
589
+ style: { marginTop: ".5rem", marginBottom: ".5rem" },
590
+ children: createDescription(description),
591
+ })
592
+ ),
593
+ ],
594
+ }),
595
+ create("div", {
596
+ children: [
597
+ create("span", {
598
+ className: "badge badge--info",
599
+ children: "oneOf",
600
+ }),
601
+ create("SchemaTabs", {
602
+ children: schema["oneOf"]!.map((property, index) => {
603
+ const label = property.type ?? `MOD${index + 1}`;
604
+ return create("TabItem", {
605
+ label: label,
606
+ value: `${index}-property`,
607
+ children: [
608
+ create("p", { children: label }),
609
+ guard(schema.description, (description) =>
610
+ create("div", {
611
+ style: { marginTop: ".5rem", marginBottom: ".5rem" },
612
+ children: createDescription(description),
613
+ })
614
+ ),
615
+ ],
616
+ });
617
+ }),
618
+ }),
619
+ ],
620
+ }),
621
+ ],
622
+ }),
623
+ ],
624
+ });
625
+ }
626
+
535
627
  /**
536
628
  * For handling discriminators that map to a same-level property (like 'petType').
537
629
  * Note: These should only be encountered while iterating through properties.
@@ -542,7 +634,7 @@ function createPropertyDiscriminator(
542
634
  schema: SchemaObject,
543
635
  discriminator: any,
544
636
  required: string[] | boolean
545
- ): any {
637
+ ) {
546
638
  if (schema === undefined) {
547
639
  return undefined;
548
640
  }
@@ -551,59 +643,26 @@ function createPropertyDiscriminator(
551
643
  return undefined;
552
644
  }
553
645
 
554
- return create("div", {
555
- className: "discriminatorItem",
556
- children: create("div", {
557
- children: [
558
- create("strong", { style: { paddingLeft: "1rem" }, children: name }),
559
- guard(schemaName, (name) =>
560
- create("span", {
561
- style: { opacity: "0.6" },
562
- children: ` ${schemaName}`,
563
- })
564
- ),
565
- guard(required, () => [
566
- create("strong", {
567
- style: {
568
- fontSize: "var(--ifm-code-font-size)",
569
- color: "var(--openapi-required)",
570
- },
571
- children: " required",
572
- }),
573
- ]),
574
- guard(getQualifierMessage(discriminator), (message) =>
575
- create("div", {
576
- style: {
577
- paddingLeft: "1rem",
578
- },
579
- children: createDescription(message),
580
- })
581
- ),
582
- guard(schema.description, (description) =>
583
- create("div", {
584
- style: {
585
- paddingLeft: "1rem",
586
- },
587
- children: createDescription(description),
588
- })
589
- ),
590
- create("DiscriminatorTabs", {
591
- children: Object.keys(discriminator?.mapping!).map((key, index) => {
592
- const label = key;
593
- return create("TabItem", {
594
- label: label,
595
- value: `${index}-item-discriminator`,
596
- children: [
597
- create("div", {
598
- style: { marginLeft: "-4px" },
599
- children: createNodes(discriminator?.mapping[key]),
600
- }),
601
- ],
602
- });
603
- }),
646
+ return create("SchemaItem", {
647
+ name,
648
+ required: Array.isArray(required) ? required.includes(name) : required,
649
+ schemaName: schemaName,
650
+ qualifierMessage: getQualifierMessage(schema),
651
+ schema: schema,
652
+ collapsible: false,
653
+ discriminator: true,
654
+ children: [
655
+ create("DiscriminatorTabs", {
656
+ children: Object.keys(discriminator?.mapping!).map((key, index) => {
657
+ const label = key;
658
+ return create("TabItem", {
659
+ label: label,
660
+ value: `${index}-item-discriminator`,
661
+ children: createNodes(discriminator?.mapping[key]),
662
+ });
604
663
  }),
605
- ],
606
- }),
664
+ }),
665
+ ],
607
666
  });
608
667
  }
609
668
 
@@ -636,7 +695,7 @@ function createEdges({
636
695
  }
637
696
 
638
697
  if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
639
- return createDetailsNode(
698
+ return createOneOfProperty(
640
699
  name,
641
700
  schemaName,
642
701
  schema,
@@ -810,30 +869,38 @@ function createNodes(schema: SchemaObject): any {
810
869
 
811
870
  // primitive
812
871
  if (schema.type !== undefined) {
813
- return create("li", {
814
- children: create("div", {
815
- children: [
816
- create("strong", { children: schema.type }),
817
- guard(schema.format, (format) =>
818
- create("span", {
819
- style: { opacity: "0.6" },
820
- children: ` ${format}`,
821
- })
822
- ),
823
- guard(getQualifierMessage(schema), (message) =>
824
- create("div", {
825
- style: { marginTop: "var(--ifm-table-cell-padding)" },
826
- children: createDescription(message),
827
- })
828
- ),
829
- guard(schema.description, (description) =>
830
- create("div", {
831
- style: { marginTop: "var(--ifm-table-cell-padding)" },
832
- children: createDescription(description),
833
- })
834
- ),
835
- ],
836
- }),
872
+ if (schema.allOf) {
873
+ //handle circular result in allOf
874
+ if (schema.allOf.length && typeof schema.allOf[0] === "string") {
875
+ return create("div", {
876
+ style: {
877
+ marginTop: ".5rem",
878
+ marginBottom: ".5rem",
879
+ marginLeft: "1rem",
880
+ },
881
+ children: createDescription(schema.allOf[0]),
882
+ });
883
+ }
884
+ }
885
+ return create("div", {
886
+ style: {
887
+ marginTop: ".5rem",
888
+ marginBottom: ".5rem",
889
+ marginLeft: "1rem",
890
+ },
891
+ children: createDescription(schema.type),
892
+ });
893
+ }
894
+
895
+ // handle circular references
896
+ if (typeof schema === "string") {
897
+ return create("div", {
898
+ style: {
899
+ marginTop: ".5rem",
900
+ marginBottom: ".5rem",
901
+ marginLeft: "1rem",
902
+ },
903
+ children: [createDescription(schema)],
837
904
  });
838
905
  }
839
906
 
@@ -101,7 +101,16 @@ async function resolveJsonRefs(specUrlOrObject: object | string) {
101
101
  });
102
102
  return schema as OpenApiObject;
103
103
  } catch (err: any) {
104
- console.error(chalk.yellow(err.errors[0]?.message ?? err));
104
+ let errorMsg = "";
105
+
106
+ if (err.errors[0] !== undefined) {
107
+ const error = err.errors[0];
108
+ errorMsg = `Error: [${error.message}] with footprint [${error.footprint}]`;
109
+ } else {
110
+ errorMsg = err;
111
+ }
112
+
113
+ console.error(chalk.yellow(errorMsg));
105
114
  return;
106
115
  }
107
116
  }
package/src/options.ts CHANGED
@@ -16,6 +16,12 @@ const sidebarOptions = Joi.object({
16
16
  sidebarCollapsed: Joi.boolean(),
17
17
  });
18
18
 
19
+ const markdownGenerators = Joi.object({
20
+ createApiPageMD: Joi.function(),
21
+ createInfoPageMD: Joi.function(),
22
+ createTagPageMD: Joi.function(),
23
+ });
24
+
19
25
  export const OptionsSchema = Joi.object({
20
26
  id: Joi.string().required(),
21
27
  docsPluginId: Joi.string().required(),
@@ -31,6 +37,7 @@ export const OptionsSchema = Joi.object({
31
37
  hideSendButton: Joi.boolean(),
32
38
  showExtensions: Joi.boolean(),
33
39
  sidebarOptions: sidebarOptions,
40
+ markdownGenerators: markdownGenerators,
34
41
  version: Joi.string().when("versions", {
35
42
  is: Joi.exist(),
36
43
  then: Joi.required(),
package/src/types.ts CHANGED
@@ -43,6 +43,13 @@ export interface APIOptions {
43
43
  [key: string]: APIVersionOptions;
44
44
  };
45
45
  proxy?: string;
46
+ markdownGenerators?: MarkdownGenerator;
47
+ }
48
+
49
+ export interface MarkdownGenerator {
50
+ createApiPageMD?: (pageData: ApiPageMetadata) => string;
51
+ createInfoPageMD?: (pageData: InfoPageMetadata) => string;
52
+ createTagPageMD?: (pageData: TagPageMetadata) => string;
46
53
  }
47
54
 
48
55
  export interface SidebarOptions {