docusaurus-plugin-openapi-docs 4.0.0 → 4.1.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/README.md +14 -3
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +21 -0
- package/lib/markdown/createCallbacks.js +2 -2
- package/lib/markdown/createDeprecationNotice.js +5 -6
- package/lib/markdown/createMethodEndpoint.js +8 -1
- package/lib/markdown/createParamsDetails.js +10 -4
- package/lib/markdown/createSchema.js +32 -22
- package/lib/markdown/createSchema.test.js +535 -0
- package/lib/markdown/utils.d.ts +4 -0
- package/lib/openapi/openapi.js +13 -13
- package/lib/openapi/types.d.ts +3 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +1 -1
- package/lib/options.js +4 -0
- package/lib/sidebars/index.js +32 -26
- package/lib/types.d.ts +9 -0
- package/package.json +6 -6
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1091 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +2 -2
- package/src/markdown/createDeprecationNotice.ts +3 -2
- package/src/markdown/createMethodEndpoint.ts +8 -1
- package/src/markdown/createParamsDetails.ts +12 -5
- package/src/markdown/createSchema.test.ts +673 -0
- package/src/markdown/createSchema.ts +39 -26
- package/src/markdown/utils.ts +4 -0
- package/src/openapi/openapi.ts +1 -1
- package/src/openapi/types.ts +3 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +1 -0
- package/src/options.ts +5 -0
- package/src/sidebars/index.ts +47 -40
- package/src/types.ts +11 -0
|
@@ -72,6 +72,199 @@ describe("createNodes", () => {
|
|
|
72
72
|
};
|
|
73
73
|
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
74
74
|
});
|
|
75
|
+
it("should handle oneOf with different primitive types", async () => {
|
|
76
|
+
const schema = {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {
|
|
79
|
+
oneOfProperty: {
|
|
80
|
+
oneOf: [
|
|
81
|
+
{ type: "string" },
|
|
82
|
+
{ type: "number" },
|
|
83
|
+
{ type: "boolean" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
89
|
+
});
|
|
90
|
+
it("should handle oneOf with complex types", async () => {
|
|
91
|
+
const schema = {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
oneOfProperty: {
|
|
95
|
+
oneOf: [
|
|
96
|
+
{
|
|
97
|
+
type: "object",
|
|
98
|
+
properties: {
|
|
99
|
+
objectProp: { type: "string" },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: "array",
|
|
104
|
+
items: { type: "number" },
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
111
|
+
});
|
|
112
|
+
it("should handle nested oneOf clauses", async () => {
|
|
113
|
+
const schema = {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
oneOfProperty: {
|
|
117
|
+
oneOf: [
|
|
118
|
+
{
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
nestedOneOfProp: {
|
|
122
|
+
oneOf: [{ type: "string" }, { type: "number" }],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{ type: "boolean" },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
132
|
+
});
|
|
133
|
+
// TypeError: Cannot read properties of undefined (reading 'length')
|
|
134
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
135
|
+
// it("should handle oneOf with discriminator", async () => {
|
|
136
|
+
// const schema: SchemaObject = {
|
|
137
|
+
// type: "object",
|
|
138
|
+
// discriminator: { propertyName: "type" },
|
|
139
|
+
// properties: {
|
|
140
|
+
// type: { type: "string" },
|
|
141
|
+
// },
|
|
142
|
+
// oneOf: [
|
|
143
|
+
// {
|
|
144
|
+
// type: "object",
|
|
145
|
+
// properties: {
|
|
146
|
+
// type: { type: "string", enum: ["typeA"] },
|
|
147
|
+
// propA: { type: "string" },
|
|
148
|
+
// },
|
|
149
|
+
// required: ["type"],
|
|
150
|
+
// },
|
|
151
|
+
// {
|
|
152
|
+
// type: "object",
|
|
153
|
+
// properties: {
|
|
154
|
+
// type: { type: "string", enum: ["typeB"] },
|
|
155
|
+
// propB: { type: "number" },
|
|
156
|
+
// },
|
|
157
|
+
// required: ["type"],
|
|
158
|
+
// },
|
|
159
|
+
// ],
|
|
160
|
+
// };
|
|
161
|
+
// expect(
|
|
162
|
+
// await Promise.all(
|
|
163
|
+
// createNodes(schema, "response").map(
|
|
164
|
+
// async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
165
|
+
// )
|
|
166
|
+
// )
|
|
167
|
+
// ).toMatchSnapshot();
|
|
168
|
+
// });
|
|
169
|
+
it("should handle oneOf with shared properties", async () => {
|
|
170
|
+
const schema = {
|
|
171
|
+
type: "object",
|
|
172
|
+
properties: {
|
|
173
|
+
sharedProp: { type: "string" },
|
|
174
|
+
oneOfProperty: {
|
|
175
|
+
oneOf: [
|
|
176
|
+
{
|
|
177
|
+
type: "object",
|
|
178
|
+
properties: {
|
|
179
|
+
specificPropA: { type: "string" },
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
specificPropB: { type: "number" },
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
193
|
+
});
|
|
194
|
+
it("should handle oneOf with required properties", async () => {
|
|
195
|
+
const schema = {
|
|
196
|
+
type: "object",
|
|
197
|
+
properties: {
|
|
198
|
+
oneOfProperty: {
|
|
199
|
+
oneOf: [
|
|
200
|
+
{
|
|
201
|
+
type: "object",
|
|
202
|
+
properties: {
|
|
203
|
+
requiredPropA: { type: "string" },
|
|
204
|
+
},
|
|
205
|
+
required: ["requiredPropA"],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: "object",
|
|
209
|
+
properties: {
|
|
210
|
+
requiredPropB: { type: "number" },
|
|
211
|
+
},
|
|
212
|
+
required: ["requiredPropB"],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe("anyOf", () => {
|
|
222
|
+
it("should render primitives within anyOf", async () => {
|
|
223
|
+
const schema = {
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
oneOfProperty: {
|
|
227
|
+
anyOf: [
|
|
228
|
+
{
|
|
229
|
+
type: "integer",
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: "boolean",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
title: "One of int or bool",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
240
|
+
});
|
|
241
|
+
it("should render oneOf within anyOf", async () => {
|
|
242
|
+
const schema = {
|
|
243
|
+
type: "object",
|
|
244
|
+
properties: {
|
|
245
|
+
oneOfProperty: {
|
|
246
|
+
anyOf: [
|
|
247
|
+
{
|
|
248
|
+
oneOf: [
|
|
249
|
+
{
|
|
250
|
+
type: "integer",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
type: "boolean",
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
title: "An int or a bool",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: "string",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
title: "One of int or bool, or a string",
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
267
|
+
});
|
|
75
268
|
});
|
|
76
269
|
describe("allOf", () => {
|
|
77
270
|
it("should render same-level properties with allOf", async () => {
|
|
@@ -289,6 +482,348 @@ describe("createNodes", () => {
|
|
|
289
482
|
// ).toMatchSnapshot();
|
|
290
483
|
// });
|
|
291
484
|
});
|
|
485
|
+
describe("discriminator", () => {
|
|
486
|
+
it("should handle basic discriminator with oneOf", async () => {
|
|
487
|
+
const schema = {
|
|
488
|
+
type: "object",
|
|
489
|
+
discriminator: { propertyName: "type" },
|
|
490
|
+
properties: {
|
|
491
|
+
type: { type: "string" },
|
|
492
|
+
},
|
|
493
|
+
oneOf: [
|
|
494
|
+
{
|
|
495
|
+
type: "object",
|
|
496
|
+
properties: {
|
|
497
|
+
type: { type: "string", enum: ["typeA"] },
|
|
498
|
+
propA: { type: "string" },
|
|
499
|
+
},
|
|
500
|
+
required: ["type"],
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
type: "object",
|
|
504
|
+
properties: {
|
|
505
|
+
type: { type: "string", enum: ["typeB"] },
|
|
506
|
+
propB: { type: "number" },
|
|
507
|
+
},
|
|
508
|
+
required: ["type"],
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
};
|
|
512
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
513
|
+
});
|
|
514
|
+
it("should handle discriminator with shared properties", async () => {
|
|
515
|
+
const schema = {
|
|
516
|
+
type: "object",
|
|
517
|
+
discriminator: { propertyName: "type" },
|
|
518
|
+
properties: {
|
|
519
|
+
type: { type: "string" },
|
|
520
|
+
sharedProp: { type: "string" },
|
|
521
|
+
},
|
|
522
|
+
oneOf: [
|
|
523
|
+
{
|
|
524
|
+
type: "object",
|
|
525
|
+
properties: {
|
|
526
|
+
type: { type: "string", enum: ["typeA"] },
|
|
527
|
+
propA: { type: "string" },
|
|
528
|
+
},
|
|
529
|
+
required: ["type"],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
type: "object",
|
|
533
|
+
properties: {
|
|
534
|
+
type: { type: "string", enum: ["typeB"] },
|
|
535
|
+
propB: { type: "number" },
|
|
536
|
+
},
|
|
537
|
+
required: ["type"],
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
};
|
|
541
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
542
|
+
});
|
|
543
|
+
it("should handle discriminator with nested schemas", async () => {
|
|
544
|
+
const schema = {
|
|
545
|
+
type: "object",
|
|
546
|
+
discriminator: { propertyName: "type" },
|
|
547
|
+
properties: {
|
|
548
|
+
type: { type: "string" },
|
|
549
|
+
},
|
|
550
|
+
oneOf: [
|
|
551
|
+
{
|
|
552
|
+
type: "object",
|
|
553
|
+
properties: {
|
|
554
|
+
type: { type: "string", enum: ["typeA"] },
|
|
555
|
+
nestedA: {
|
|
556
|
+
type: "object",
|
|
557
|
+
properties: {
|
|
558
|
+
propA1: { type: "string" },
|
|
559
|
+
propA2: { type: "number" },
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
required: ["type"],
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
type: "object",
|
|
567
|
+
properties: {
|
|
568
|
+
type: { type: "string", enum: ["typeB"] },
|
|
569
|
+
nestedB: {
|
|
570
|
+
type: "object",
|
|
571
|
+
properties: {
|
|
572
|
+
propB1: { type: "string" },
|
|
573
|
+
propB2: { type: "boolean" },
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
required: ["type"],
|
|
578
|
+
},
|
|
579
|
+
],
|
|
580
|
+
};
|
|
581
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
582
|
+
});
|
|
583
|
+
it("should handle discriminator with additional properties", async () => {
|
|
584
|
+
const schema = {
|
|
585
|
+
type: "object",
|
|
586
|
+
discriminator: { propertyName: "type" },
|
|
587
|
+
properties: {
|
|
588
|
+
type: { type: "string" },
|
|
589
|
+
},
|
|
590
|
+
oneOf: [
|
|
591
|
+
{
|
|
592
|
+
type: "object",
|
|
593
|
+
properties: {
|
|
594
|
+
type: { type: "string", enum: ["typeA"] },
|
|
595
|
+
propA: { type: "string" },
|
|
596
|
+
},
|
|
597
|
+
additionalProperties: false,
|
|
598
|
+
required: ["type"],
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
type: "object",
|
|
602
|
+
properties: {
|
|
603
|
+
type: { type: "string", enum: ["typeB"] },
|
|
604
|
+
propB: { type: "number" },
|
|
605
|
+
},
|
|
606
|
+
additionalProperties: true,
|
|
607
|
+
required: ["type"],
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
};
|
|
611
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
612
|
+
});
|
|
613
|
+
it("should handle discriminator with allOf", async () => {
|
|
614
|
+
const schema = {
|
|
615
|
+
type: "object",
|
|
616
|
+
discriminator: { propertyName: "type" },
|
|
617
|
+
properties: {
|
|
618
|
+
type: { type: "string" },
|
|
619
|
+
},
|
|
620
|
+
allOf: [
|
|
621
|
+
{
|
|
622
|
+
oneOf: [
|
|
623
|
+
{
|
|
624
|
+
type: "object",
|
|
625
|
+
properties: {
|
|
626
|
+
type: { type: "string", enum: ["typeA"] },
|
|
627
|
+
propA: { type: "string" },
|
|
628
|
+
},
|
|
629
|
+
required: ["type"],
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
type: "object",
|
|
633
|
+
properties: {
|
|
634
|
+
type: { type: "string", enum: ["typeB"] },
|
|
635
|
+
propB: { type: "number" },
|
|
636
|
+
},
|
|
637
|
+
required: ["type"],
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
type: "object",
|
|
643
|
+
properties: {
|
|
644
|
+
sharedProp: { type: "string" },
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
],
|
|
648
|
+
};
|
|
649
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
650
|
+
});
|
|
651
|
+
it("should handle discriminator with required properties", async () => {
|
|
652
|
+
const schema = {
|
|
653
|
+
type: "object",
|
|
654
|
+
discriminator: { propertyName: "type" },
|
|
655
|
+
properties: {
|
|
656
|
+
type: { type: "string" },
|
|
657
|
+
},
|
|
658
|
+
oneOf: [
|
|
659
|
+
{
|
|
660
|
+
type: "object",
|
|
661
|
+
properties: {
|
|
662
|
+
type: { type: "string", enum: ["typeA"] },
|
|
663
|
+
propA: { type: "string" },
|
|
664
|
+
},
|
|
665
|
+
required: ["type", "propA"],
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
type: "object",
|
|
669
|
+
properties: {
|
|
670
|
+
type: { type: "string", enum: ["typeB"] },
|
|
671
|
+
propB: { type: "number" },
|
|
672
|
+
},
|
|
673
|
+
required: ["type", "propB"],
|
|
674
|
+
},
|
|
675
|
+
],
|
|
676
|
+
};
|
|
677
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
678
|
+
});
|
|
679
|
+
it("should handle basic discriminator with mapping", async () => {
|
|
680
|
+
const schema = {
|
|
681
|
+
type: "object",
|
|
682
|
+
discriminator: {
|
|
683
|
+
propertyName: "type",
|
|
684
|
+
mapping: {
|
|
685
|
+
typeA: "#/definitions/TypeA",
|
|
686
|
+
typeB: "#/definitions/TypeB",
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
properties: {
|
|
690
|
+
type: { type: "string" },
|
|
691
|
+
},
|
|
692
|
+
oneOf: [
|
|
693
|
+
{
|
|
694
|
+
type: "object",
|
|
695
|
+
properties: {
|
|
696
|
+
type: { type: "string", enum: ["typeA"] },
|
|
697
|
+
propA: { type: "string" },
|
|
698
|
+
},
|
|
699
|
+
required: ["type"],
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
type: "object",
|
|
703
|
+
properties: {
|
|
704
|
+
type: { type: "string", enum: ["typeB"] },
|
|
705
|
+
propB: { type: "number" },
|
|
706
|
+
},
|
|
707
|
+
required: ["type"],
|
|
708
|
+
},
|
|
709
|
+
],
|
|
710
|
+
};
|
|
711
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
712
|
+
});
|
|
713
|
+
it("should handle discriminator with shared properties and mapping", async () => {
|
|
714
|
+
const schema = {
|
|
715
|
+
type: "object",
|
|
716
|
+
discriminator: {
|
|
717
|
+
propertyName: "type",
|
|
718
|
+
mapping: {
|
|
719
|
+
typeA: "#/definitions/TypeA",
|
|
720
|
+
typeB: "#/definitions/TypeB",
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
properties: {
|
|
724
|
+
type: { type: "string" },
|
|
725
|
+
sharedProp: { type: "string" },
|
|
726
|
+
},
|
|
727
|
+
oneOf: [
|
|
728
|
+
{
|
|
729
|
+
type: "object",
|
|
730
|
+
properties: {
|
|
731
|
+
type: { type: "string", enum: ["typeA"] },
|
|
732
|
+
propA: { type: "string" },
|
|
733
|
+
},
|
|
734
|
+
required: ["type"],
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
type: "object",
|
|
738
|
+
properties: {
|
|
739
|
+
type: { type: "string", enum: ["typeB"] },
|
|
740
|
+
propB: { type: "number" },
|
|
741
|
+
},
|
|
742
|
+
required: ["type"],
|
|
743
|
+
},
|
|
744
|
+
],
|
|
745
|
+
};
|
|
746
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
747
|
+
});
|
|
748
|
+
it("should handle discriminator with allOf and mapping", async () => {
|
|
749
|
+
const schema = {
|
|
750
|
+
type: "object",
|
|
751
|
+
discriminator: {
|
|
752
|
+
propertyName: "type",
|
|
753
|
+
mapping: {
|
|
754
|
+
typeA: "#/definitions/TypeA",
|
|
755
|
+
typeB: "#/definitions/TypeB",
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
properties: {
|
|
759
|
+
type: { type: "string" },
|
|
760
|
+
},
|
|
761
|
+
allOf: [
|
|
762
|
+
{
|
|
763
|
+
oneOf: [
|
|
764
|
+
{
|
|
765
|
+
type: "object",
|
|
766
|
+
properties: {
|
|
767
|
+
type: { type: "string", enum: ["typeA"] },
|
|
768
|
+
propA: { type: "string" },
|
|
769
|
+
},
|
|
770
|
+
required: ["type"],
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
type: "object",
|
|
774
|
+
properties: {
|
|
775
|
+
type: { type: "string", enum: ["typeB"] },
|
|
776
|
+
propB: { type: "number" },
|
|
777
|
+
},
|
|
778
|
+
required: ["type"],
|
|
779
|
+
},
|
|
780
|
+
],
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
type: "object",
|
|
784
|
+
properties: {
|
|
785
|
+
sharedProp: { type: "string" },
|
|
786
|
+
},
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
};
|
|
790
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
791
|
+
});
|
|
792
|
+
it("should handle discriminator with required properties and mapping", async () => {
|
|
793
|
+
const schema = {
|
|
794
|
+
type: "object",
|
|
795
|
+
discriminator: {
|
|
796
|
+
propertyName: "type",
|
|
797
|
+
mapping: {
|
|
798
|
+
typeA: "#/definitions/TypeA",
|
|
799
|
+
typeB: "#/definitions/TypeB",
|
|
800
|
+
},
|
|
801
|
+
},
|
|
802
|
+
properties: {
|
|
803
|
+
type: { type: "string" },
|
|
804
|
+
},
|
|
805
|
+
oneOf: [
|
|
806
|
+
{
|
|
807
|
+
type: "object",
|
|
808
|
+
properties: {
|
|
809
|
+
type: { type: "string", enum: ["typeA"] },
|
|
810
|
+
propA: { type: "string" },
|
|
811
|
+
},
|
|
812
|
+
required: ["type", "propA"],
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
type: "object",
|
|
816
|
+
properties: {
|
|
817
|
+
type: { type: "string", enum: ["typeB"] },
|
|
818
|
+
propB: { type: "number" },
|
|
819
|
+
},
|
|
820
|
+
required: ["type", "propB"],
|
|
821
|
+
},
|
|
822
|
+
],
|
|
823
|
+
};
|
|
824
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
825
|
+
});
|
|
826
|
+
});
|
|
292
827
|
describe("additionalProperties", () => {
|
|
293
828
|
it.each([
|
|
294
829
|
[
|
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Children in the plugin does not accept DOM elements, when compared with Children in the theme.
|
|
3
|
+
* It is designed for rendering HTML a strings.
|
|
4
|
+
*/
|
|
1
5
|
export type Children = string | undefined | (string | string[] | undefined)[];
|
|
2
6
|
export type Props = Record<string, any> & {
|
|
3
7
|
children?: Children;
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -61,7 +61,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
61
61
|
return await jsonToCollection(data);
|
|
62
62
|
}
|
|
63
63
|
function createItems(openapiData, options, sidebarOptions) {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
|
|
65
65
|
// TODO: Find a better way to handle this
|
|
66
66
|
let items = [];
|
|
67
67
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
@@ -212,15 +212,15 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
// Gather x-webhooks endpoints
|
|
215
|
-
for (let [path, pathObject] of Object.entries((_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : {})) {
|
|
215
|
+
for (let [path, pathObject] of Object.entries((_q = (_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : openapiData["webhooks"]) !== null && _q !== void 0 ? _q : {})) {
|
|
216
216
|
path = "webhook";
|
|
217
217
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
218
218
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
219
219
|
method = "event";
|
|
220
|
-
const title = (
|
|
220
|
+
const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
|
|
221
221
|
if (operationObject.description === undefined) {
|
|
222
222
|
operationObject.description =
|
|
223
|
-
(
|
|
223
|
+
(_u = (_t = operationObject.summary) !== null && _t !== void 0 ? _t : operationObject.operationId) !== null && _u !== void 0 ? _u : "";
|
|
224
224
|
}
|
|
225
225
|
const baseId = operationObject.operationId
|
|
226
226
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
@@ -232,10 +232,10 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
232
232
|
extensions.push({ key, value });
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
const servers = (
|
|
236
|
-
const security = (
|
|
235
|
+
const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
|
|
236
|
+
const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
|
|
237
237
|
// Add security schemes so we know how to handle security.
|
|
238
|
-
const securitySchemes = (
|
|
238
|
+
const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
|
|
239
239
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
240
240
|
if (securitySchemes) {
|
|
241
241
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -245,7 +245,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
let jsonRequestBodyExample;
|
|
248
|
-
const content = (
|
|
248
|
+
const content = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
|
|
249
249
|
let body;
|
|
250
250
|
for (let key in content) {
|
|
251
251
|
if (key.toLowerCase() === "application/json" ||
|
|
@@ -258,7 +258,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
258
258
|
jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
|
|
259
259
|
}
|
|
260
260
|
// Handle vendor JSON media types
|
|
261
|
-
const bodyContent = (
|
|
261
|
+
const bodyContent = (_0 = operationObject.requestBody) === null || _0 === void 0 ? void 0 : _0.content;
|
|
262
262
|
if (bodyContent) {
|
|
263
263
|
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
264
264
|
if (firstBodyContentKey.endsWith("+json")) {
|
|
@@ -325,13 +325,13 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
|
|
328
|
-
Object.entries((
|
|
328
|
+
Object.entries((_2 = (_1 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _1 === void 0 ? void 0 : _1.schemas) !== null && _2 !== void 0 ? _2 : {})
|
|
329
329
|
.flatMap(([_, s]) => s["x-tags"])
|
|
330
330
|
.filter((item) => !!item).length > 0) {
|
|
331
331
|
// Gather schemas
|
|
332
|
-
for (let [schema, schemaObject] of Object.entries((
|
|
332
|
+
for (let [schema, schemaObject] of Object.entries((_4 = (_3 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _3 === void 0 ? void 0 : _3.schemas) !== null && _4 !== void 0 ? _4 : {})) {
|
|
333
333
|
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
|
|
334
|
-
const baseIdSpaces = (
|
|
334
|
+
const baseIdSpaces = (_6 = (_5 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _5 === void 0 ? void 0 : _5.replace(" ", "-").toLowerCase()) !== null && _6 !== void 0 ? _6 : "";
|
|
335
335
|
const baseId = (0, kebabCase_1.default)(baseIdSpaces);
|
|
336
336
|
const schemaDescription = schemaObject.description;
|
|
337
337
|
let splitDescription;
|
|
@@ -364,7 +364,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
364
364
|
}
|
|
365
365
|
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
366
366
|
// Get global tags
|
|
367
|
-
const tags = (
|
|
367
|
+
const tags = (_7 = openapiData.tags) !== null && _7 !== void 0 ? _7 : [];
|
|
368
368
|
// Get operation tags
|
|
369
369
|
const apiItems = items.filter((item) => {
|
|
370
370
|
return item.type === "api";
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface OpenApiObject {
|
|
|
12
12
|
tags?: TagObject[];
|
|
13
13
|
externalDocs?: ExternalDocumentationObject;
|
|
14
14
|
swagger?: string;
|
|
15
|
+
webhooks?: PathsObject;
|
|
15
16
|
"x-webhooks"?: PathsObject;
|
|
16
17
|
"x-tagGroups"?: TagGroupObject[];
|
|
17
18
|
}
|
|
@@ -163,6 +164,7 @@ export interface ParameterObject {
|
|
|
163
164
|
examples?: Map<ExampleObject>;
|
|
164
165
|
content?: Map<MediaTypeObject>;
|
|
165
166
|
param?: Object;
|
|
167
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
166
168
|
}
|
|
167
169
|
export interface ParameterObjectWithRef {
|
|
168
170
|
name: string;
|
|
@@ -279,6 +281,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
|
|
|
279
281
|
example?: any;
|
|
280
282
|
deprecated?: boolean;
|
|
281
283
|
"x-tags"?: string[];
|
|
284
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
282
285
|
};
|
|
283
286
|
export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
284
287
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
@@ -215,7 +215,7 @@ class OpenAPIParser {
|
|
|
215
215
|
})
|
|
216
216
|
.filter((child) => child !== undefined);
|
|
217
217
|
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
|
|
218
|
-
const { type, enum: enumProperty, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
|
|
218
|
+
const { type, enum: enumProperty, "x-enumDescription": enumDescription, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
|
|
219
219
|
if (receiver.type !== type &&
|
|
220
220
|
receiver.type !== undefined &&
|
|
221
221
|
type !== undefined) {
|