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.
- package/lib/index.js +8 -4
- package/lib/markdown/createRequestSchema.js +167 -101
- package/lib/markdown/createResponseSchema.js +167 -101
- package/lib/openapi/utils/loadAndResolveSpec.js +9 -2
- package/lib/options.js +6 -0
- package/lib/types.d.ts +6 -0
- package/package.json +2 -2
- package/src/index.ts +18 -5
- package/src/markdown/createRequestSchema.ts +192 -125
- package/src/markdown/createResponseSchema.ts +192 -125
- package/src/openapi/utils/loadAndResolveSpec.ts +10 -1
- package/src/options.ts +7 -0
- package/src/types.ts +7 -0
|
@@ -53,7 +53,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
53
53
|
*/
|
|
54
54
|
function createAnyOneOf(schema: SchemaObject): any {
|
|
55
55
|
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
56
|
-
return create("
|
|
56
|
+
return create("div", {
|
|
57
57
|
children: [
|
|
58
58
|
create("span", {
|
|
59
59
|
className: "badge badge--info",
|
|
@@ -68,14 +68,17 @@ function createAnyOneOf(schema: SchemaObject): any {
|
|
|
68
68
|
|
|
69
69
|
if (anyOneSchema.properties !== undefined) {
|
|
70
70
|
anyOneChildren.push(createProperties(anyOneSchema));
|
|
71
|
+
delete anyOneSchema.properties;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
if (anyOneSchema.allOf !== undefined) {
|
|
74
75
|
anyOneChildren.push(createNodes(anyOneSchema));
|
|
76
|
+
delete anyOneSchema.allOf;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
if (anyOneSchema.items !== undefined) {
|
|
78
80
|
anyOneChildren.push(createItems(anyOneSchema));
|
|
81
|
+
delete anyOneSchema.items;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
if (
|
|
@@ -159,6 +162,18 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
159
162
|
// }
|
|
160
163
|
const additionalProperties = schema.additionalProperties;
|
|
161
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
|
+
}
|
|
162
177
|
if (
|
|
163
178
|
(type === "object" || type === "array") &&
|
|
164
179
|
(additionalProperties?.properties ||
|
|
@@ -168,12 +183,12 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
168
183
|
additionalProperties?.oneOf ||
|
|
169
184
|
additionalProperties?.anyOf)
|
|
170
185
|
) {
|
|
171
|
-
const title = additionalProperties.title;
|
|
172
|
-
const schemaName =
|
|
186
|
+
const title = additionalProperties.title as string;
|
|
187
|
+
const schemaName = getSchemaName(additionalProperties);
|
|
173
188
|
const required = schema.required ?? false;
|
|
174
189
|
return createDetailsNode(
|
|
175
190
|
"property name*",
|
|
176
|
-
schemaName,
|
|
191
|
+
title ?? schemaName,
|
|
177
192
|
additionalProperties,
|
|
178
193
|
required,
|
|
179
194
|
schema.nullable
|
|
@@ -191,51 +206,30 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
191
206
|
schema.additionalProperties?.additionalProperties;
|
|
192
207
|
if (additionalProperties !== undefined) {
|
|
193
208
|
const type = schema.additionalProperties?.additionalProperties?.type;
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
style: { opacity: "0.6" },
|
|
208
|
-
children: ` (${format})`,
|
|
209
|
-
})
|
|
210
|
-
),
|
|
211
|
-
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
212
|
-
create("div", {
|
|
213
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
214
|
-
children: createDescription(message),
|
|
215
|
-
})
|
|
216
|
-
),
|
|
217
|
-
],
|
|
218
|
-
}),
|
|
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,
|
|
219
222
|
});
|
|
220
223
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
),
|
|
231
|
-
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
232
|
-
create("div", {
|
|
233
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
234
|
-
children: createDescription(message),
|
|
235
|
-
})
|
|
236
|
-
),
|
|
237
|
-
],
|
|
238
|
-
}),
|
|
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,
|
|
239
233
|
});
|
|
240
234
|
}
|
|
241
235
|
return Object.entries(schema.additionalProperties!).map(([key, val]) =>
|
|
@@ -526,6 +520,104 @@ function createDetailsNode(
|
|
|
526
520
|
});
|
|
527
521
|
}
|
|
528
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
|
+
|
|
529
621
|
/**
|
|
530
622
|
* For handling discriminators that map to a same-level property (like 'petType').
|
|
531
623
|
* Note: These should only be encountered while iterating through properties.
|
|
@@ -536,7 +628,7 @@ function createPropertyDiscriminator(
|
|
|
536
628
|
schema: SchemaObject,
|
|
537
629
|
discriminator: any,
|
|
538
630
|
required: string[] | boolean
|
|
539
|
-
)
|
|
631
|
+
) {
|
|
540
632
|
if (schema === undefined) {
|
|
541
633
|
return undefined;
|
|
542
634
|
}
|
|
@@ -545,59 +637,26 @@ function createPropertyDiscriminator(
|
|
|
545
637
|
return undefined;
|
|
546
638
|
}
|
|
547
639
|
|
|
548
|
-
return create("
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
),
|
|
559
|
-
|
|
560
|
-
create("
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
children: " required",
|
|
566
|
-
}),
|
|
567
|
-
]),
|
|
568
|
-
guard(getQualifierMessage(discriminator), (message) =>
|
|
569
|
-
create("div", {
|
|
570
|
-
style: {
|
|
571
|
-
paddingLeft: "1rem",
|
|
572
|
-
},
|
|
573
|
-
children: createDescription(message),
|
|
574
|
-
})
|
|
575
|
-
),
|
|
576
|
-
guard(schema.description, (description) =>
|
|
577
|
-
create("div", {
|
|
578
|
-
style: {
|
|
579
|
-
paddingLeft: "1rem",
|
|
580
|
-
},
|
|
581
|
-
children: createDescription(description),
|
|
582
|
-
})
|
|
583
|
-
),
|
|
584
|
-
create("DiscriminatorTabs", {
|
|
585
|
-
children: Object.keys(discriminator?.mapping!).map((key, index) => {
|
|
586
|
-
const label = key;
|
|
587
|
-
return create("TabItem", {
|
|
588
|
-
label: label,
|
|
589
|
-
value: `${index}-item-discriminator`,
|
|
590
|
-
children: [
|
|
591
|
-
create("div", {
|
|
592
|
-
style: { marginLeft: "-4px" },
|
|
593
|
-
children: createNodes(discriminator?.mapping[key]),
|
|
594
|
-
}),
|
|
595
|
-
],
|
|
596
|
-
});
|
|
597
|
-
}),
|
|
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
|
+
});
|
|
598
657
|
}),
|
|
599
|
-
|
|
600
|
-
|
|
658
|
+
}),
|
|
659
|
+
],
|
|
601
660
|
});
|
|
602
661
|
}
|
|
603
662
|
|
|
@@ -630,7 +689,7 @@ function createEdges({
|
|
|
630
689
|
}
|
|
631
690
|
|
|
632
691
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
633
|
-
return
|
|
692
|
+
return createOneOfProperty(
|
|
634
693
|
name,
|
|
635
694
|
schemaName,
|
|
636
695
|
schema,
|
|
@@ -802,30 +861,38 @@ function createNodes(schema: SchemaObject): any {
|
|
|
802
861
|
|
|
803
862
|
// primitive
|
|
804
863
|
if (schema.type !== undefined) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
),
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
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)],
|
|
829
896
|
});
|
|
830
897
|
}
|
|
831
898
|
|