docusaurus-plugin-openapi-docs 1.5.1-hotfix1 → 1.5.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.
- package/LICENSE +21 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +37 -0
- package/lib/markdown/createRequestSchema.js +119 -79
- package/lib/markdown/createResponseSchema.js +123 -82
- package/lib/markdown/createStatusCodes.js +4 -6
- package/lib/openapi/createRequestExample.js +26 -7
- package/lib/openapi/createResponseExample.js +26 -7
- package/lib/openapi/utils/loadAndResolveSpec.js +1 -1
- package/package.json +4 -3
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createRequestSchema.ts +136 -95
- package/src/markdown/createResponseSchema.ts +143 -98
- package/src/markdown/createStatusCodes.ts +4 -8
- package/src/openapi/createRequestExample.ts +35 -12
- package/src/openapi/createResponseExample.ts +35 -12
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
|
@@ -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
|
/**
|
|
@@ -414,6 +451,15 @@ function createDetailsNode(
|
|
|
414
451
|
style: { opacity: "0.6" },
|
|
415
452
|
children: ` ${schemaName}`,
|
|
416
453
|
}),
|
|
454
|
+
guard(schema.nullable && schema.nullable === true, () => [
|
|
455
|
+
create("strong", {
|
|
456
|
+
style: {
|
|
457
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
458
|
+
color: "var(--openapi-nullable)",
|
|
459
|
+
},
|
|
460
|
+
children: " nullable",
|
|
461
|
+
}),
|
|
462
|
+
]),
|
|
417
463
|
guard(
|
|
418
464
|
Array.isArray(required)
|
|
419
465
|
? required.includes(name)
|
|
@@ -597,11 +643,9 @@ function createEdges({
|
|
|
597
643
|
collapsible: false,
|
|
598
644
|
name,
|
|
599
645
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
600
|
-
deprecated: mergedSchemas.deprecated,
|
|
601
|
-
schemaDescription: mergedSchemas.description,
|
|
602
646
|
schemaName: schemaName,
|
|
603
647
|
qualifierMessage: getQualifierMessage(schema),
|
|
604
|
-
|
|
648
|
+
schema: mergedSchemas,
|
|
605
649
|
});
|
|
606
650
|
}
|
|
607
651
|
|
|
@@ -631,11 +675,9 @@ function createEdges({
|
|
|
631
675
|
collapsible: false,
|
|
632
676
|
name,
|
|
633
677
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
634
|
-
deprecated: schema.deprecated,
|
|
635
|
-
schemaDescription: schema.description,
|
|
636
678
|
schemaName: schemaName,
|
|
637
679
|
qualifierMessage: getQualifierMessage(schema),
|
|
638
|
-
|
|
680
|
+
schema: schema,
|
|
639
681
|
});
|
|
640
682
|
}
|
|
641
683
|
|
|
@@ -643,12 +685,13 @@ function createEdges({
|
|
|
643
685
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
644
686
|
*/
|
|
645
687
|
function createNodes(schema: SchemaObject): any {
|
|
688
|
+
const nodes = [];
|
|
646
689
|
// if (schema.discriminator !== undefined) {
|
|
647
690
|
// return createDiscriminator(schema);
|
|
648
691
|
// }
|
|
649
692
|
|
|
650
693
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
651
|
-
|
|
694
|
+
nodes.push(createAnyOneOf(schema));
|
|
652
695
|
}
|
|
653
696
|
|
|
654
697
|
if (schema.allOf !== undefined) {
|
|
@@ -656,21 +699,25 @@ function createNodes(schema: SchemaObject): any {
|
|
|
656
699
|
|
|
657
700
|
// allOf seems to always result in properties
|
|
658
701
|
if (mergedSchemas.properties !== undefined) {
|
|
659
|
-
|
|
702
|
+
nodes.push(createProperties(mergedSchemas));
|
|
660
703
|
}
|
|
661
704
|
}
|
|
662
705
|
|
|
663
706
|
if (schema.properties !== undefined) {
|
|
664
|
-
|
|
707
|
+
nodes.push(createProperties(schema));
|
|
665
708
|
}
|
|
666
709
|
|
|
667
710
|
if (schema.additionalProperties !== undefined) {
|
|
668
|
-
|
|
711
|
+
nodes.push(createAdditionalProperties(schema));
|
|
669
712
|
}
|
|
670
713
|
|
|
671
714
|
// TODO: figure out how to handle array of objects
|
|
672
715
|
if (schema.items !== undefined) {
|
|
673
|
-
|
|
716
|
+
nodes.push(createItems(schema));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (nodes.length && nodes.length > 0) {
|
|
720
|
+
return nodes.filter(Boolean).flat();
|
|
674
721
|
}
|
|
675
722
|
|
|
676
723
|
// primitive
|
|
@@ -758,12 +805,6 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
758
805
|
style: { textAlign: "left" },
|
|
759
806
|
children: [
|
|
760
807
|
create("strong", { children: `${title}` }),
|
|
761
|
-
guard(firstBody.type === "array", (format) =>
|
|
762
|
-
create("span", {
|
|
763
|
-
style: { opacity: "0.6" },
|
|
764
|
-
children: ` array`,
|
|
765
|
-
})
|
|
766
|
-
),
|
|
767
808
|
guard(body.required && body.required === true, () => [
|
|
768
809
|
create("strong", {
|
|
769
810
|
style: {
|