docusaurus-plugin-openapi-docs 3.0.2 → 4.0.1
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 +5 -4
- package/lib/markdown/createSchema.js +2 -1
- package/lib/markdown/createSchema.test.js +487 -0
- package/package.json +2 -2
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1004 -0
- package/src/markdown/createSchema.test.ts +609 -0
- package/src/markdown/createSchema.ts +2 -1
|
@@ -57,6 +57,193 @@ describe("createNodes", () => {
|
|
|
57
57
|
)
|
|
58
58
|
).toMatchSnapshot();
|
|
59
59
|
});
|
|
60
|
+
|
|
61
|
+
it("should handle oneOf with different primitive types", async () => {
|
|
62
|
+
const schema: SchemaObject = {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
oneOfProperty: {
|
|
66
|
+
oneOf: [
|
|
67
|
+
{ type: "string" },
|
|
68
|
+
{ type: "number" },
|
|
69
|
+
{ type: "boolean" },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
expect(
|
|
76
|
+
await Promise.all(
|
|
77
|
+
createNodes(schema, "response").map(
|
|
78
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should handle oneOf with complex types", async () => {
|
|
85
|
+
const schema: SchemaObject = {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
oneOfProperty: {
|
|
89
|
+
oneOf: [
|
|
90
|
+
{
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: {
|
|
93
|
+
objectProp: { type: "string" },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: "array",
|
|
98
|
+
items: { type: "number" },
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
expect(
|
|
106
|
+
await Promise.all(
|
|
107
|
+
createNodes(schema, "response").map(
|
|
108
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should handle nested oneOf clauses", async () => {
|
|
115
|
+
const schema: SchemaObject = {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
oneOfProperty: {
|
|
119
|
+
oneOf: [
|
|
120
|
+
{
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
nestedOneOfProp: {
|
|
124
|
+
oneOf: [{ type: "string" }, { type: "number" }],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{ type: "boolean" },
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
expect(
|
|
135
|
+
await Promise.all(
|
|
136
|
+
createNodes(schema, "response").map(
|
|
137
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
).toMatchSnapshot();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// TypeError: Cannot read properties of undefined (reading 'length')
|
|
144
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
145
|
+
// it("should handle oneOf with discriminator", async () => {
|
|
146
|
+
// const schema: SchemaObject = {
|
|
147
|
+
// type: "object",
|
|
148
|
+
// discriminator: { propertyName: "type" },
|
|
149
|
+
// properties: {
|
|
150
|
+
// type: { type: "string" },
|
|
151
|
+
// },
|
|
152
|
+
// oneOf: [
|
|
153
|
+
// {
|
|
154
|
+
// type: "object",
|
|
155
|
+
// properties: {
|
|
156
|
+
// type: { type: "string", enum: ["typeA"] },
|
|
157
|
+
// propA: { type: "string" },
|
|
158
|
+
// },
|
|
159
|
+
// required: ["type"],
|
|
160
|
+
// },
|
|
161
|
+
// {
|
|
162
|
+
// type: "object",
|
|
163
|
+
// properties: {
|
|
164
|
+
// type: { type: "string", enum: ["typeB"] },
|
|
165
|
+
// propB: { type: "number" },
|
|
166
|
+
// },
|
|
167
|
+
// required: ["type"],
|
|
168
|
+
// },
|
|
169
|
+
// ],
|
|
170
|
+
// };
|
|
171
|
+
|
|
172
|
+
// expect(
|
|
173
|
+
// await Promise.all(
|
|
174
|
+
// createNodes(schema, "response").map(
|
|
175
|
+
// async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
176
|
+
// )
|
|
177
|
+
// )
|
|
178
|
+
// ).toMatchSnapshot();
|
|
179
|
+
// });
|
|
180
|
+
|
|
181
|
+
it("should handle oneOf with shared properties", async () => {
|
|
182
|
+
const schema: SchemaObject = {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
sharedProp: { type: "string" },
|
|
186
|
+
oneOfProperty: {
|
|
187
|
+
oneOf: [
|
|
188
|
+
{
|
|
189
|
+
type: "object",
|
|
190
|
+
properties: {
|
|
191
|
+
specificPropA: { type: "string" },
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: {
|
|
197
|
+
specificPropB: { type: "number" },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
expect(
|
|
206
|
+
await Promise.all(
|
|
207
|
+
createNodes(schema, "response").map(
|
|
208
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
).toMatchSnapshot();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should handle oneOf with required properties", async () => {
|
|
215
|
+
const schema: SchemaObject = {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {
|
|
218
|
+
oneOfProperty: {
|
|
219
|
+
oneOf: [
|
|
220
|
+
{
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
requiredPropA: { type: "string" },
|
|
224
|
+
},
|
|
225
|
+
required: ["requiredPropA"],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
type: "object",
|
|
229
|
+
properties: {
|
|
230
|
+
requiredPropB: { type: "number" },
|
|
231
|
+
},
|
|
232
|
+
required: ["requiredPropB"],
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
expect(
|
|
240
|
+
await Promise.all(
|
|
241
|
+
createNodes(schema, "response").map(
|
|
242
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
).toMatchSnapshot();
|
|
246
|
+
});
|
|
60
247
|
});
|
|
61
248
|
|
|
62
249
|
describe("allOf", () => {
|
|
@@ -313,6 +500,428 @@ describe("createNodes", () => {
|
|
|
313
500
|
// });
|
|
314
501
|
});
|
|
315
502
|
|
|
503
|
+
describe("discriminator", () => {
|
|
504
|
+
it("should handle basic discriminator with oneOf", async () => {
|
|
505
|
+
const schema: SchemaObject = {
|
|
506
|
+
type: "object",
|
|
507
|
+
discriminator: { propertyName: "type" },
|
|
508
|
+
properties: {
|
|
509
|
+
type: { type: "string" },
|
|
510
|
+
},
|
|
511
|
+
oneOf: [
|
|
512
|
+
{
|
|
513
|
+
type: "object",
|
|
514
|
+
properties: {
|
|
515
|
+
type: { type: "string", enum: ["typeA"] },
|
|
516
|
+
propA: { type: "string" },
|
|
517
|
+
},
|
|
518
|
+
required: ["type"],
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
type: "object",
|
|
522
|
+
properties: {
|
|
523
|
+
type: { type: "string", enum: ["typeB"] },
|
|
524
|
+
propB: { type: "number" },
|
|
525
|
+
},
|
|
526
|
+
required: ["type"],
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
expect(
|
|
532
|
+
await Promise.all(
|
|
533
|
+
createNodes(schema, "response").map(
|
|
534
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
535
|
+
)
|
|
536
|
+
)
|
|
537
|
+
).toMatchSnapshot();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("should handle discriminator with shared properties", async () => {
|
|
541
|
+
const schema: SchemaObject = {
|
|
542
|
+
type: "object",
|
|
543
|
+
discriminator: { propertyName: "type" },
|
|
544
|
+
properties: {
|
|
545
|
+
type: { type: "string" },
|
|
546
|
+
sharedProp: { type: "string" },
|
|
547
|
+
},
|
|
548
|
+
oneOf: [
|
|
549
|
+
{
|
|
550
|
+
type: "object",
|
|
551
|
+
properties: {
|
|
552
|
+
type: { type: "string", enum: ["typeA"] },
|
|
553
|
+
propA: { type: "string" },
|
|
554
|
+
},
|
|
555
|
+
required: ["type"],
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
type: "object",
|
|
559
|
+
properties: {
|
|
560
|
+
type: { type: "string", enum: ["typeB"] },
|
|
561
|
+
propB: { type: "number" },
|
|
562
|
+
},
|
|
563
|
+
required: ["type"],
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
expect(
|
|
569
|
+
await Promise.all(
|
|
570
|
+
createNodes(schema, "response").map(
|
|
571
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
572
|
+
)
|
|
573
|
+
)
|
|
574
|
+
).toMatchSnapshot();
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it("should handle discriminator with nested schemas", async () => {
|
|
578
|
+
const schema: SchemaObject = {
|
|
579
|
+
type: "object",
|
|
580
|
+
discriminator: { propertyName: "type" },
|
|
581
|
+
properties: {
|
|
582
|
+
type: { type: "string" },
|
|
583
|
+
},
|
|
584
|
+
oneOf: [
|
|
585
|
+
{
|
|
586
|
+
type: "object",
|
|
587
|
+
properties: {
|
|
588
|
+
type: { type: "string", enum: ["typeA"] },
|
|
589
|
+
nestedA: {
|
|
590
|
+
type: "object",
|
|
591
|
+
properties: {
|
|
592
|
+
propA1: { type: "string" },
|
|
593
|
+
propA2: { type: "number" },
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
required: ["type"],
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
type: "object",
|
|
601
|
+
properties: {
|
|
602
|
+
type: { type: "string", enum: ["typeB"] },
|
|
603
|
+
nestedB: {
|
|
604
|
+
type: "object",
|
|
605
|
+
properties: {
|
|
606
|
+
propB1: { type: "string" },
|
|
607
|
+
propB2: { type: "boolean" },
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
required: ["type"],
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
expect(
|
|
617
|
+
await Promise.all(
|
|
618
|
+
createNodes(schema, "response").map(
|
|
619
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
620
|
+
)
|
|
621
|
+
)
|
|
622
|
+
).toMatchSnapshot();
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("should handle discriminator with additional properties", async () => {
|
|
626
|
+
const schema: SchemaObject = {
|
|
627
|
+
type: "object",
|
|
628
|
+
discriminator: { propertyName: "type" },
|
|
629
|
+
properties: {
|
|
630
|
+
type: { type: "string" },
|
|
631
|
+
},
|
|
632
|
+
oneOf: [
|
|
633
|
+
{
|
|
634
|
+
type: "object",
|
|
635
|
+
properties: {
|
|
636
|
+
type: { type: "string", enum: ["typeA"] },
|
|
637
|
+
propA: { type: "string" },
|
|
638
|
+
},
|
|
639
|
+
additionalProperties: false,
|
|
640
|
+
required: ["type"],
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
type: "object",
|
|
644
|
+
properties: {
|
|
645
|
+
type: { type: "string", enum: ["typeB"] },
|
|
646
|
+
propB: { type: "number" },
|
|
647
|
+
},
|
|
648
|
+
additionalProperties: true,
|
|
649
|
+
required: ["type"],
|
|
650
|
+
},
|
|
651
|
+
],
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
expect(
|
|
655
|
+
await Promise.all(
|
|
656
|
+
createNodes(schema, "response").map(
|
|
657
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
658
|
+
)
|
|
659
|
+
)
|
|
660
|
+
).toMatchSnapshot();
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("should handle discriminator with allOf", async () => {
|
|
664
|
+
const schema: SchemaObject = {
|
|
665
|
+
type: "object",
|
|
666
|
+
discriminator: { propertyName: "type" },
|
|
667
|
+
properties: {
|
|
668
|
+
type: { type: "string" },
|
|
669
|
+
},
|
|
670
|
+
allOf: [
|
|
671
|
+
{
|
|
672
|
+
oneOf: [
|
|
673
|
+
{
|
|
674
|
+
type: "object",
|
|
675
|
+
properties: {
|
|
676
|
+
type: { type: "string", enum: ["typeA"] },
|
|
677
|
+
propA: { type: "string" },
|
|
678
|
+
},
|
|
679
|
+
required: ["type"],
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
type: "object",
|
|
683
|
+
properties: {
|
|
684
|
+
type: { type: "string", enum: ["typeB"] },
|
|
685
|
+
propB: { type: "number" },
|
|
686
|
+
},
|
|
687
|
+
required: ["type"],
|
|
688
|
+
},
|
|
689
|
+
],
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
type: "object",
|
|
693
|
+
properties: {
|
|
694
|
+
sharedProp: { type: "string" },
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
],
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
expect(
|
|
701
|
+
await Promise.all(
|
|
702
|
+
createNodes(schema, "response").map(
|
|
703
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
704
|
+
)
|
|
705
|
+
)
|
|
706
|
+
).toMatchSnapshot();
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
it("should handle discriminator with required properties", async () => {
|
|
710
|
+
const schema: SchemaObject = {
|
|
711
|
+
type: "object",
|
|
712
|
+
discriminator: { propertyName: "type" },
|
|
713
|
+
properties: {
|
|
714
|
+
type: { type: "string" },
|
|
715
|
+
},
|
|
716
|
+
oneOf: [
|
|
717
|
+
{
|
|
718
|
+
type: "object",
|
|
719
|
+
properties: {
|
|
720
|
+
type: { type: "string", enum: ["typeA"] },
|
|
721
|
+
propA: { type: "string" },
|
|
722
|
+
},
|
|
723
|
+
required: ["type", "propA"],
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
type: "object",
|
|
727
|
+
properties: {
|
|
728
|
+
type: { type: "string", enum: ["typeB"] },
|
|
729
|
+
propB: { type: "number" },
|
|
730
|
+
},
|
|
731
|
+
required: ["type", "propB"],
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
expect(
|
|
737
|
+
await Promise.all(
|
|
738
|
+
createNodes(schema, "response").map(
|
|
739
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
740
|
+
)
|
|
741
|
+
)
|
|
742
|
+
).toMatchSnapshot();
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
it("should handle basic discriminator with mapping", async () => {
|
|
746
|
+
const schema: SchemaObject = {
|
|
747
|
+
type: "object",
|
|
748
|
+
discriminator: {
|
|
749
|
+
propertyName: "type",
|
|
750
|
+
mapping: {
|
|
751
|
+
typeA: "#/definitions/TypeA",
|
|
752
|
+
typeB: "#/definitions/TypeB",
|
|
753
|
+
},
|
|
754
|
+
},
|
|
755
|
+
properties: {
|
|
756
|
+
type: { type: "string" },
|
|
757
|
+
},
|
|
758
|
+
oneOf: [
|
|
759
|
+
{
|
|
760
|
+
type: "object",
|
|
761
|
+
properties: {
|
|
762
|
+
type: { type: "string", enum: ["typeA"] },
|
|
763
|
+
propA: { type: "string" },
|
|
764
|
+
},
|
|
765
|
+
required: ["type"],
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
type: "object",
|
|
769
|
+
properties: {
|
|
770
|
+
type: { type: "string", enum: ["typeB"] },
|
|
771
|
+
propB: { type: "number" },
|
|
772
|
+
},
|
|
773
|
+
required: ["type"],
|
|
774
|
+
},
|
|
775
|
+
],
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
expect(
|
|
779
|
+
await Promise.all(
|
|
780
|
+
createNodes(schema, "response").map(
|
|
781
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
782
|
+
)
|
|
783
|
+
)
|
|
784
|
+
).toMatchSnapshot();
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it("should handle discriminator with shared properties and mapping", async () => {
|
|
788
|
+
const schema: SchemaObject = {
|
|
789
|
+
type: "object",
|
|
790
|
+
discriminator: {
|
|
791
|
+
propertyName: "type",
|
|
792
|
+
mapping: {
|
|
793
|
+
typeA: "#/definitions/TypeA",
|
|
794
|
+
typeB: "#/definitions/TypeB",
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
properties: {
|
|
798
|
+
type: { type: "string" },
|
|
799
|
+
sharedProp: { type: "string" },
|
|
800
|
+
},
|
|
801
|
+
oneOf: [
|
|
802
|
+
{
|
|
803
|
+
type: "object",
|
|
804
|
+
properties: {
|
|
805
|
+
type: { type: "string", enum: ["typeA"] },
|
|
806
|
+
propA: { type: "string" },
|
|
807
|
+
},
|
|
808
|
+
required: ["type"],
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
type: "object",
|
|
812
|
+
properties: {
|
|
813
|
+
type: { type: "string", enum: ["typeB"] },
|
|
814
|
+
propB: { type: "number" },
|
|
815
|
+
},
|
|
816
|
+
required: ["type"],
|
|
817
|
+
},
|
|
818
|
+
],
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
expect(
|
|
822
|
+
await Promise.all(
|
|
823
|
+
createNodes(schema, "response").map(
|
|
824
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
825
|
+
)
|
|
826
|
+
)
|
|
827
|
+
).toMatchSnapshot();
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it("should handle discriminator with allOf and mapping", async () => {
|
|
831
|
+
const schema: SchemaObject = {
|
|
832
|
+
type: "object",
|
|
833
|
+
discriminator: {
|
|
834
|
+
propertyName: "type",
|
|
835
|
+
mapping: {
|
|
836
|
+
typeA: "#/definitions/TypeA",
|
|
837
|
+
typeB: "#/definitions/TypeB",
|
|
838
|
+
},
|
|
839
|
+
},
|
|
840
|
+
properties: {
|
|
841
|
+
type: { type: "string" },
|
|
842
|
+
},
|
|
843
|
+
allOf: [
|
|
844
|
+
{
|
|
845
|
+
oneOf: [
|
|
846
|
+
{
|
|
847
|
+
type: "object",
|
|
848
|
+
properties: {
|
|
849
|
+
type: { type: "string", enum: ["typeA"] },
|
|
850
|
+
propA: { type: "string" },
|
|
851
|
+
},
|
|
852
|
+
required: ["type"],
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
type: "object",
|
|
856
|
+
properties: {
|
|
857
|
+
type: { type: "string", enum: ["typeB"] },
|
|
858
|
+
propB: { type: "number" },
|
|
859
|
+
},
|
|
860
|
+
required: ["type"],
|
|
861
|
+
},
|
|
862
|
+
],
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
type: "object",
|
|
866
|
+
properties: {
|
|
867
|
+
sharedProp: { type: "string" },
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
],
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
expect(
|
|
874
|
+
await Promise.all(
|
|
875
|
+
createNodes(schema, "response").map(
|
|
876
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
877
|
+
)
|
|
878
|
+
)
|
|
879
|
+
).toMatchSnapshot();
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
it("should handle discriminator with required properties and mapping", async () => {
|
|
883
|
+
const schema: SchemaObject = {
|
|
884
|
+
type: "object",
|
|
885
|
+
discriminator: {
|
|
886
|
+
propertyName: "type",
|
|
887
|
+
mapping: {
|
|
888
|
+
typeA: "#/definitions/TypeA",
|
|
889
|
+
typeB: "#/definitions/TypeB",
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
properties: {
|
|
893
|
+
type: { type: "string" },
|
|
894
|
+
},
|
|
895
|
+
oneOf: [
|
|
896
|
+
{
|
|
897
|
+
type: "object",
|
|
898
|
+
properties: {
|
|
899
|
+
type: { type: "string", enum: ["typeA"] },
|
|
900
|
+
propA: { type: "string" },
|
|
901
|
+
},
|
|
902
|
+
required: ["type", "propA"],
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
type: "object",
|
|
906
|
+
properties: {
|
|
907
|
+
type: { type: "string", enum: ["typeB"] },
|
|
908
|
+
propB: { type: "number" },
|
|
909
|
+
},
|
|
910
|
+
required: ["type", "propB"],
|
|
911
|
+
},
|
|
912
|
+
],
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
expect(
|
|
916
|
+
await Promise.all(
|
|
917
|
+
createNodes(schema, "response").map(
|
|
918
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
919
|
+
)
|
|
920
|
+
)
|
|
921
|
+
).toMatchSnapshot();
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
|
|
316
925
|
describe("additionalProperties", () => {
|
|
317
926
|
it.each([
|
|
318
927
|
[
|
|
@@ -524,8 +524,9 @@ function createPropertyDiscriminator(
|
|
|
524
524
|
return undefined;
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
+
// render as a simple property if there's no mapping
|
|
527
528
|
if (discriminator.mapping === undefined) {
|
|
528
|
-
return
|
|
529
|
+
return createEdges({ name, schema, required });
|
|
529
530
|
}
|
|
530
531
|
|
|
531
532
|
return create("div", {
|