docusaurus-plugin-openapi-docs 1.5.1 → 1.6.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.
- package/lib/index.js +5 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +37 -0
- package/lib/markdown/createAuthentication.js +45 -13
- package/lib/markdown/createRequestSchema.js +133 -91
- package/lib/markdown/createResponseSchema.js +140 -95
- package/lib/markdown/createStatusCodes.js +7 -7
- package/lib/markdown/index.js +1 -1
- package/lib/openapi/createRequestExample.js +27 -8
- package/lib/openapi/createResponseExample.js +27 -8
- package/lib/openapi/openapi.js +7 -1
- package/lib/openapi/utils/loadAndResolveSpec.js +13 -0
- package/lib/options.js +1 -0
- package/lib/sidebars/index.js +3 -1
- package/lib/types.d.ts +1 -0
- package/package.json +8 -8
- package/src/index.ts +6 -0
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createAuthentication.ts +53 -17
- package/src/markdown/createRequestSchema.ts +208 -107
- package/src/markdown/createResponseSchema.ts +228 -119
- package/src/markdown/createStatusCodes.ts +42 -47
- package/src/markdown/index.ts +1 -1
- package/src/openapi/createRequestExample.ts +36 -13
- package/src/openapi/createResponseExample.ts +36 -13
- package/src/openapi/openapi.ts +7 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +15 -0
- package/src/options.ts +1 -0
- package/src/sidebars/index.ts +6 -1
- package/src/types.ts +1 -0
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
9
|
+
import {
|
|
10
|
+
createClosingArrayBracket,
|
|
11
|
+
createOpeningArrayBracket,
|
|
12
|
+
} from "./createArrayBracket";
|
|
9
13
|
import { createDescription } from "./createDescription";
|
|
10
14
|
import { createDetails } from "./createDetails";
|
|
11
15
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
@@ -49,54 +53,62 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
49
53
|
*/
|
|
50
54
|
function createAnyOneOf(schema: SchemaObject): any {
|
|
51
55
|
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
52
|
-
return create("
|
|
56
|
+
return create("li", {
|
|
53
57
|
children: [
|
|
54
|
-
create("
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
72
|
+
|
|
73
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
74
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (anyOneSchema.items !== undefined) {
|
|
78
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
anyOneSchema.type === "string" ||
|
|
83
|
+
anyOneSchema.type === "number" ||
|
|
84
|
+
anyOneSchema.type === "integer" ||
|
|
85
|
+
anyOneSchema.type === "boolean"
|
|
86
|
+
) {
|
|
87
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
88
|
+
}
|
|
89
|
+
if (anyOneChildren.length) {
|
|
90
|
+
if (schema.type === "array") {
|
|
91
|
+
return create("TabItem", {
|
|
92
|
+
label: label,
|
|
93
|
+
value: `${index}-item-properties`,
|
|
94
|
+
children: [
|
|
95
|
+
createOpeningArrayBracket(),
|
|
96
|
+
anyOneChildren,
|
|
97
|
+
createClosingArrayBracket(),
|
|
98
|
+
]
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.flat(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return create("TabItem", {
|
|
104
|
+
label: label,
|
|
105
|
+
value: `${index}-item-properties`,
|
|
106
|
+
children: anyOneChildren.filter(Boolean).flat(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return undefined;
|
|
111
|
+
}),
|
|
100
112
|
}),
|
|
101
113
|
],
|
|
102
114
|
});
|
|
@@ -147,11 +159,11 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
147
159
|
// }
|
|
148
160
|
|
|
149
161
|
if (
|
|
150
|
-
schema.additionalProperties?.type === "string" ||
|
|
151
|
-
schema.additionalProperties?.type === "object" ||
|
|
152
|
-
schema.additionalProperties?.type === "boolean" ||
|
|
153
|
-
schema.additionalProperties?.type === "integer" ||
|
|
154
|
-
schema.additionalProperties?.type === "number"
|
|
162
|
+
(schema.additionalProperties?.type as string) === "string" ||
|
|
163
|
+
(schema.additionalProperties?.type as string) === "object" ||
|
|
164
|
+
(schema.additionalProperties?.type as string) === "boolean" ||
|
|
165
|
+
(schema.additionalProperties?.type as string) === "integer" ||
|
|
166
|
+
(schema.additionalProperties?.type as string) === "number"
|
|
155
167
|
) {
|
|
156
168
|
const type = schema.additionalProperties?.type;
|
|
157
169
|
const additionalProperties =
|
|
@@ -219,15 +231,27 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
219
231
|
// TODO: figure out how to handle array of objects
|
|
220
232
|
function createItems(schema: SchemaObject) {
|
|
221
233
|
if (schema.items?.properties !== undefined) {
|
|
222
|
-
return
|
|
234
|
+
return [
|
|
235
|
+
createOpeningArrayBracket(),
|
|
236
|
+
createProperties(schema.items),
|
|
237
|
+
createClosingArrayBracket(),
|
|
238
|
+
].flat();
|
|
223
239
|
}
|
|
224
240
|
|
|
225
241
|
if (schema.items?.additionalProperties !== undefined) {
|
|
226
|
-
return
|
|
242
|
+
return [
|
|
243
|
+
createOpeningArrayBracket(),
|
|
244
|
+
createAdditionalProperties(schema.items),
|
|
245
|
+
createClosingArrayBracket(),
|
|
246
|
+
].flat();
|
|
227
247
|
}
|
|
228
248
|
|
|
229
249
|
if (schema.items?.oneOf !== undefined || schema.items?.anyOf !== undefined) {
|
|
230
|
-
return
|
|
250
|
+
return [
|
|
251
|
+
createOpeningArrayBracket(),
|
|
252
|
+
createAnyOneOf(schema.items!),
|
|
253
|
+
createClosingArrayBracket(),
|
|
254
|
+
].flat();
|
|
231
255
|
}
|
|
232
256
|
|
|
233
257
|
if (schema.items?.allOf !== undefined) {
|
|
@@ -244,12 +268,12 @@ function createItems(schema: SchemaObject) {
|
|
|
244
268
|
mergedSchemas.anyOf !== undefined) &&
|
|
245
269
|
mergedSchemas.properties
|
|
246
270
|
) {
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
271
|
+
return [
|
|
272
|
+
createOpeningArrayBracket(),
|
|
273
|
+
createAnyOneOf(mergedSchemas),
|
|
274
|
+
createProperties(mergedSchemas),
|
|
275
|
+
createClosingArrayBracket(),
|
|
276
|
+
].flat();
|
|
253
277
|
}
|
|
254
278
|
|
|
255
279
|
// Handles only anyOf/oneOf
|
|
@@ -257,16 +281,20 @@ function createItems(schema: SchemaObject) {
|
|
|
257
281
|
mergedSchemas.oneOf !== undefined ||
|
|
258
282
|
mergedSchemas.anyOf !== undefined
|
|
259
283
|
) {
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
|
|
284
|
+
return [
|
|
285
|
+
createOpeningArrayBracket(),
|
|
286
|
+
createAnyOneOf(mergedSchemas),
|
|
287
|
+
createClosingArrayBracket(),
|
|
288
|
+
].flat();
|
|
263
289
|
}
|
|
264
290
|
|
|
265
291
|
// Handles properties
|
|
266
292
|
if (mergedSchemas.properties !== undefined) {
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
293
|
+
return [
|
|
294
|
+
createOpeningArrayBracket(),
|
|
295
|
+
createProperties(mergedSchemas),
|
|
296
|
+
createClosingArrayBracket(),
|
|
297
|
+
].flat();
|
|
270
298
|
}
|
|
271
299
|
}
|
|
272
300
|
|
|
@@ -274,21 +302,30 @@ function createItems(schema: SchemaObject) {
|
|
|
274
302
|
schema.items?.type === "string" ||
|
|
275
303
|
schema.items?.type === "number" ||
|
|
276
304
|
schema.items?.type === "integer" ||
|
|
277
|
-
schema.items?.type === "boolean"
|
|
305
|
+
schema.items?.type === "boolean" ||
|
|
306
|
+
schema.items?.type === "object"
|
|
278
307
|
) {
|
|
279
|
-
return
|
|
308
|
+
return [
|
|
309
|
+
createOpeningArrayBracket(),
|
|
310
|
+
createNodes(schema.items),
|
|
311
|
+
createClosingArrayBracket(),
|
|
312
|
+
].flat();
|
|
280
313
|
}
|
|
281
314
|
|
|
282
315
|
// TODO: clean this up or eliminate it?
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
:
|
|
290
|
-
|
|
291
|
-
|
|
316
|
+
return [
|
|
317
|
+
createOpeningArrayBracket(),
|
|
318
|
+
Object.entries(schema.items!).map(([key, val]) =>
|
|
319
|
+
createEdges({
|
|
320
|
+
name: key,
|
|
321
|
+
schema: val,
|
|
322
|
+
required: Array.isArray(schema.required)
|
|
323
|
+
? schema.required.includes(key)
|
|
324
|
+
: false,
|
|
325
|
+
})
|
|
326
|
+
),
|
|
327
|
+
createClosingArrayBracket(),
|
|
328
|
+
].flat();
|
|
292
329
|
}
|
|
293
330
|
|
|
294
331
|
/**
|
|
@@ -399,7 +436,8 @@ function createDetailsNode(
|
|
|
399
436
|
name: string,
|
|
400
437
|
schemaName: string,
|
|
401
438
|
schema: SchemaObject,
|
|
402
|
-
required: string[] | boolean
|
|
439
|
+
required: string[] | boolean,
|
|
440
|
+
nullable: boolean | unknown
|
|
403
441
|
): any {
|
|
404
442
|
return create("SchemaItem", {
|
|
405
443
|
collapsible: true,
|
|
@@ -414,6 +452,19 @@ function createDetailsNode(
|
|
|
414
452
|
style: { opacity: "0.6" },
|
|
415
453
|
children: ` ${schemaName}`,
|
|
416
454
|
}),
|
|
455
|
+
guard(
|
|
456
|
+
(schema.nullable && schema.nullable === true) ||
|
|
457
|
+
(nullable && nullable === true),
|
|
458
|
+
() => [
|
|
459
|
+
create("strong", {
|
|
460
|
+
style: {
|
|
461
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
462
|
+
color: "var(--openapi-nullable)",
|
|
463
|
+
},
|
|
464
|
+
children: " nullable",
|
|
465
|
+
}),
|
|
466
|
+
]
|
|
467
|
+
),
|
|
417
468
|
guard(
|
|
418
469
|
Array.isArray(required)
|
|
419
470
|
? required.includes(name)
|
|
@@ -558,7 +609,13 @@ function createEdges({
|
|
|
558
609
|
}
|
|
559
610
|
|
|
560
611
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
561
|
-
return createDetailsNode(
|
|
612
|
+
return createDetailsNode(
|
|
613
|
+
name,
|
|
614
|
+
schemaName,
|
|
615
|
+
schema,
|
|
616
|
+
required,
|
|
617
|
+
schema.nullable
|
|
618
|
+
);
|
|
562
619
|
}
|
|
563
620
|
|
|
564
621
|
if (schema.allOf !== undefined) {
|
|
@@ -573,20 +630,44 @@ function createEdges({
|
|
|
573
630
|
mergedSchemas.oneOf !== undefined ||
|
|
574
631
|
mergedSchemas.anyOf !== undefined
|
|
575
632
|
) {
|
|
576
|
-
return createDetailsNode(
|
|
633
|
+
return createDetailsNode(
|
|
634
|
+
name,
|
|
635
|
+
mergedSchemaName,
|
|
636
|
+
mergedSchemas,
|
|
637
|
+
required,
|
|
638
|
+
schema.nullable
|
|
639
|
+
);
|
|
577
640
|
}
|
|
578
641
|
|
|
579
642
|
if (mergedSchemas.properties !== undefined) {
|
|
580
|
-
return createDetailsNode(
|
|
643
|
+
return createDetailsNode(
|
|
644
|
+
name,
|
|
645
|
+
mergedSchemaName,
|
|
646
|
+
mergedSchemas,
|
|
647
|
+
required,
|
|
648
|
+
schema.nullable
|
|
649
|
+
);
|
|
581
650
|
}
|
|
582
651
|
|
|
583
652
|
if (mergedSchemas.additionalProperties !== undefined) {
|
|
584
|
-
return createDetailsNode(
|
|
653
|
+
return createDetailsNode(
|
|
654
|
+
name,
|
|
655
|
+
mergedSchemaName,
|
|
656
|
+
mergedSchemas,
|
|
657
|
+
required,
|
|
658
|
+
schema.nullable
|
|
659
|
+
);
|
|
585
660
|
}
|
|
586
661
|
|
|
587
662
|
// array of objects
|
|
588
663
|
if (mergedSchemas.items?.properties !== undefined) {
|
|
589
|
-
return createDetailsNode(
|
|
664
|
+
return createDetailsNode(
|
|
665
|
+
name,
|
|
666
|
+
mergedSchemaName,
|
|
667
|
+
mergedSchemas,
|
|
668
|
+
required,
|
|
669
|
+
schema.nullable
|
|
670
|
+
);
|
|
590
671
|
}
|
|
591
672
|
|
|
592
673
|
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
@@ -597,29 +678,51 @@ function createEdges({
|
|
|
597
678
|
collapsible: false,
|
|
598
679
|
name,
|
|
599
680
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
600
|
-
deprecated: mergedSchemas.deprecated,
|
|
601
|
-
schemaDescription: mergedSchemas.description,
|
|
602
681
|
schemaName: schemaName,
|
|
603
682
|
qualifierMessage: getQualifierMessage(schema),
|
|
604
|
-
|
|
683
|
+
schema: mergedSchemas,
|
|
605
684
|
});
|
|
606
685
|
}
|
|
607
686
|
|
|
608
687
|
if (schema.properties !== undefined) {
|
|
609
|
-
return createDetailsNode(
|
|
688
|
+
return createDetailsNode(
|
|
689
|
+
name,
|
|
690
|
+
schemaName,
|
|
691
|
+
schema,
|
|
692
|
+
required,
|
|
693
|
+
schema.nullable
|
|
694
|
+
);
|
|
610
695
|
}
|
|
611
696
|
|
|
612
697
|
if (schema.additionalProperties !== undefined) {
|
|
613
|
-
return createDetailsNode(
|
|
698
|
+
return createDetailsNode(
|
|
699
|
+
name,
|
|
700
|
+
schemaName,
|
|
701
|
+
schema,
|
|
702
|
+
required,
|
|
703
|
+
schema.nullable
|
|
704
|
+
);
|
|
614
705
|
}
|
|
615
706
|
|
|
616
707
|
// array of objects
|
|
617
708
|
if (schema.items?.properties !== undefined) {
|
|
618
|
-
return createDetailsNode(
|
|
709
|
+
return createDetailsNode(
|
|
710
|
+
name,
|
|
711
|
+
schemaName,
|
|
712
|
+
schema,
|
|
713
|
+
required,
|
|
714
|
+
schema.nullable
|
|
715
|
+
);
|
|
619
716
|
}
|
|
620
717
|
|
|
621
718
|
if (schema.items?.anyOf !== undefined || schema.items?.oneOf !== undefined) {
|
|
622
|
-
return createDetailsNode(
|
|
719
|
+
return createDetailsNode(
|
|
720
|
+
name,
|
|
721
|
+
schemaName,
|
|
722
|
+
schema,
|
|
723
|
+
required,
|
|
724
|
+
schema.nullable
|
|
725
|
+
);
|
|
623
726
|
}
|
|
624
727
|
|
|
625
728
|
if (schema.readOnly && schema.readOnly === true) {
|
|
@@ -631,11 +734,9 @@ function createEdges({
|
|
|
631
734
|
collapsible: false,
|
|
632
735
|
name,
|
|
633
736
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
634
|
-
deprecated: schema.deprecated,
|
|
635
|
-
schemaDescription: schema.description,
|
|
636
737
|
schemaName: schemaName,
|
|
637
738
|
qualifierMessage: getQualifierMessage(schema),
|
|
638
|
-
|
|
739
|
+
schema: schema,
|
|
639
740
|
});
|
|
640
741
|
}
|
|
641
742
|
|
|
@@ -643,12 +744,13 @@ function createEdges({
|
|
|
643
744
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
644
745
|
*/
|
|
645
746
|
function createNodes(schema: SchemaObject): any {
|
|
747
|
+
const nodes = [];
|
|
646
748
|
// if (schema.discriminator !== undefined) {
|
|
647
749
|
// return createDiscriminator(schema);
|
|
648
750
|
// }
|
|
649
751
|
|
|
650
752
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
651
|
-
|
|
753
|
+
nodes.push(createAnyOneOf(schema));
|
|
652
754
|
}
|
|
653
755
|
|
|
654
756
|
if (schema.allOf !== undefined) {
|
|
@@ -656,21 +758,25 @@ function createNodes(schema: SchemaObject): any {
|
|
|
656
758
|
|
|
657
759
|
// allOf seems to always result in properties
|
|
658
760
|
if (mergedSchemas.properties !== undefined) {
|
|
659
|
-
|
|
761
|
+
nodes.push(createProperties(mergedSchemas));
|
|
660
762
|
}
|
|
661
763
|
}
|
|
662
764
|
|
|
663
765
|
if (schema.properties !== undefined) {
|
|
664
|
-
|
|
766
|
+
nodes.push(createProperties(schema));
|
|
665
767
|
}
|
|
666
768
|
|
|
667
769
|
if (schema.additionalProperties !== undefined) {
|
|
668
|
-
|
|
770
|
+
nodes.push(createAdditionalProperties(schema));
|
|
669
771
|
}
|
|
670
772
|
|
|
671
773
|
// TODO: figure out how to handle array of objects
|
|
672
774
|
if (schema.items !== undefined) {
|
|
673
|
-
|
|
775
|
+
nodes.push(createItems(schema));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (nodes.length && nodes.length > 0) {
|
|
779
|
+
return nodes.filter(Boolean).flat();
|
|
674
780
|
}
|
|
675
781
|
|
|
676
782
|
// primitive
|
|
@@ -704,7 +810,7 @@ function createNodes(schema: SchemaObject): any {
|
|
|
704
810
|
|
|
705
811
|
// Unknown node/schema type should return undefined
|
|
706
812
|
// So far, haven't seen this hit in testing
|
|
707
|
-
return
|
|
813
|
+
return "any";
|
|
708
814
|
}
|
|
709
815
|
|
|
710
816
|
interface Props {
|
|
@@ -758,12 +864,6 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
758
864
|
style: { textAlign: "left" },
|
|
759
865
|
children: [
|
|
760
866
|
create("strong", { children: `${title}` }),
|
|
761
|
-
guard(firstBody.type === "array", (format) =>
|
|
762
|
-
create("span", {
|
|
763
|
-
style: { opacity: "0.6" },
|
|
764
|
-
children: ` array`,
|
|
765
|
-
})
|
|
766
|
-
),
|
|
767
867
|
guard(body.required && body.required === true, () => [
|
|
768
868
|
create("strong", {
|
|
769
869
|
style: {
|
|
@@ -799,7 +899,8 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
799
899
|
}
|
|
800
900
|
|
|
801
901
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
802
|
-
const firstBody =
|
|
902
|
+
const firstBody: any =
|
|
903
|
+
body.content[randomFirstKey].schema ?? body.content![randomFirstKey];
|
|
803
904
|
|
|
804
905
|
if (firstBody === undefined) {
|
|
805
906
|
return undefined;
|