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.
@@ -57,6 +57,257 @@ 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
+ });
247
+ });
248
+
249
+ describe("anyOf", () => {
250
+ it("should render primitives within anyOf", async () => {
251
+ const schema: SchemaObject = {
252
+ type: "object",
253
+ properties: {
254
+ oneOfProperty: {
255
+ anyOf: [
256
+ {
257
+ type: "integer",
258
+ },
259
+ {
260
+ type: "boolean",
261
+ },
262
+ ],
263
+ title: "One of int or bool",
264
+ },
265
+ },
266
+ };
267
+
268
+ expect(
269
+ await Promise.all(
270
+ createNodes(schema, "response").map(
271
+ async (md: any) => await prettier.format(md, { parser: "babel" })
272
+ )
273
+ )
274
+ ).toMatchSnapshot();
275
+ });
276
+
277
+ it("should render oneOf within anyOf", async () => {
278
+ const schema: SchemaObject = {
279
+ type: "object",
280
+ properties: {
281
+ oneOfProperty: {
282
+ anyOf: [
283
+ {
284
+ oneOf: [
285
+ {
286
+ type: "integer",
287
+ },
288
+ {
289
+ type: "boolean",
290
+ },
291
+ ],
292
+ title: "An int or a bool",
293
+ },
294
+ {
295
+ type: "string",
296
+ },
297
+ ],
298
+ title: "One of int or bool, or a string",
299
+ },
300
+ },
301
+ };
302
+
303
+ expect(
304
+ await Promise.all(
305
+ createNodes(schema, "response").map(
306
+ async (md: any) => await prettier.format(md, { parser: "babel" })
307
+ )
308
+ )
309
+ ).toMatchSnapshot();
310
+ });
60
311
  });
61
312
 
62
313
  describe("allOf", () => {
@@ -313,6 +564,428 @@ describe("createNodes", () => {
313
564
  // });
314
565
  });
315
566
 
567
+ describe("discriminator", () => {
568
+ it("should handle basic discriminator with oneOf", async () => {
569
+ const schema: SchemaObject = {
570
+ type: "object",
571
+ discriminator: { propertyName: "type" },
572
+ properties: {
573
+ type: { type: "string" },
574
+ },
575
+ oneOf: [
576
+ {
577
+ type: "object",
578
+ properties: {
579
+ type: { type: "string", enum: ["typeA"] },
580
+ propA: { type: "string" },
581
+ },
582
+ required: ["type"],
583
+ },
584
+ {
585
+ type: "object",
586
+ properties: {
587
+ type: { type: "string", enum: ["typeB"] },
588
+ propB: { type: "number" },
589
+ },
590
+ required: ["type"],
591
+ },
592
+ ],
593
+ };
594
+
595
+ expect(
596
+ await Promise.all(
597
+ createNodes(schema, "response").map(
598
+ async (md: any) => await prettier.format(md, { parser: "babel" })
599
+ )
600
+ )
601
+ ).toMatchSnapshot();
602
+ });
603
+
604
+ it("should handle discriminator with shared properties", async () => {
605
+ const schema: SchemaObject = {
606
+ type: "object",
607
+ discriminator: { propertyName: "type" },
608
+ properties: {
609
+ type: { type: "string" },
610
+ sharedProp: { type: "string" },
611
+ },
612
+ oneOf: [
613
+ {
614
+ type: "object",
615
+ properties: {
616
+ type: { type: "string", enum: ["typeA"] },
617
+ propA: { type: "string" },
618
+ },
619
+ required: ["type"],
620
+ },
621
+ {
622
+ type: "object",
623
+ properties: {
624
+ type: { type: "string", enum: ["typeB"] },
625
+ propB: { type: "number" },
626
+ },
627
+ required: ["type"],
628
+ },
629
+ ],
630
+ };
631
+
632
+ expect(
633
+ await Promise.all(
634
+ createNodes(schema, "response").map(
635
+ async (md: any) => await prettier.format(md, { parser: "babel" })
636
+ )
637
+ )
638
+ ).toMatchSnapshot();
639
+ });
640
+
641
+ it("should handle discriminator with nested schemas", async () => {
642
+ const schema: SchemaObject = {
643
+ type: "object",
644
+ discriminator: { propertyName: "type" },
645
+ properties: {
646
+ type: { type: "string" },
647
+ },
648
+ oneOf: [
649
+ {
650
+ type: "object",
651
+ properties: {
652
+ type: { type: "string", enum: ["typeA"] },
653
+ nestedA: {
654
+ type: "object",
655
+ properties: {
656
+ propA1: { type: "string" },
657
+ propA2: { type: "number" },
658
+ },
659
+ },
660
+ },
661
+ required: ["type"],
662
+ },
663
+ {
664
+ type: "object",
665
+ properties: {
666
+ type: { type: "string", enum: ["typeB"] },
667
+ nestedB: {
668
+ type: "object",
669
+ properties: {
670
+ propB1: { type: "string" },
671
+ propB2: { type: "boolean" },
672
+ },
673
+ },
674
+ },
675
+ required: ["type"],
676
+ },
677
+ ],
678
+ };
679
+
680
+ expect(
681
+ await Promise.all(
682
+ createNodes(schema, "response").map(
683
+ async (md: any) => await prettier.format(md, { parser: "babel" })
684
+ )
685
+ )
686
+ ).toMatchSnapshot();
687
+ });
688
+
689
+ it("should handle discriminator with additional properties", async () => {
690
+ const schema: SchemaObject = {
691
+ type: "object",
692
+ discriminator: { propertyName: "type" },
693
+ properties: {
694
+ type: { type: "string" },
695
+ },
696
+ oneOf: [
697
+ {
698
+ type: "object",
699
+ properties: {
700
+ type: { type: "string", enum: ["typeA"] },
701
+ propA: { type: "string" },
702
+ },
703
+ additionalProperties: false,
704
+ required: ["type"],
705
+ },
706
+ {
707
+ type: "object",
708
+ properties: {
709
+ type: { type: "string", enum: ["typeB"] },
710
+ propB: { type: "number" },
711
+ },
712
+ additionalProperties: true,
713
+ required: ["type"],
714
+ },
715
+ ],
716
+ };
717
+
718
+ expect(
719
+ await Promise.all(
720
+ createNodes(schema, "response").map(
721
+ async (md: any) => await prettier.format(md, { parser: "babel" })
722
+ )
723
+ )
724
+ ).toMatchSnapshot();
725
+ });
726
+
727
+ it("should handle discriminator with allOf", async () => {
728
+ const schema: SchemaObject = {
729
+ type: "object",
730
+ discriminator: { propertyName: "type" },
731
+ properties: {
732
+ type: { type: "string" },
733
+ },
734
+ allOf: [
735
+ {
736
+ oneOf: [
737
+ {
738
+ type: "object",
739
+ properties: {
740
+ type: { type: "string", enum: ["typeA"] },
741
+ propA: { type: "string" },
742
+ },
743
+ required: ["type"],
744
+ },
745
+ {
746
+ type: "object",
747
+ properties: {
748
+ type: { type: "string", enum: ["typeB"] },
749
+ propB: { type: "number" },
750
+ },
751
+ required: ["type"],
752
+ },
753
+ ],
754
+ },
755
+ {
756
+ type: "object",
757
+ properties: {
758
+ sharedProp: { type: "string" },
759
+ },
760
+ },
761
+ ],
762
+ };
763
+
764
+ expect(
765
+ await Promise.all(
766
+ createNodes(schema, "response").map(
767
+ async (md: any) => await prettier.format(md, { parser: "babel" })
768
+ )
769
+ )
770
+ ).toMatchSnapshot();
771
+ });
772
+
773
+ it("should handle discriminator with required properties", async () => {
774
+ const schema: SchemaObject = {
775
+ type: "object",
776
+ discriminator: { propertyName: "type" },
777
+ properties: {
778
+ type: { type: "string" },
779
+ },
780
+ oneOf: [
781
+ {
782
+ type: "object",
783
+ properties: {
784
+ type: { type: "string", enum: ["typeA"] },
785
+ propA: { type: "string" },
786
+ },
787
+ required: ["type", "propA"],
788
+ },
789
+ {
790
+ type: "object",
791
+ properties: {
792
+ type: { type: "string", enum: ["typeB"] },
793
+ propB: { type: "number" },
794
+ },
795
+ required: ["type", "propB"],
796
+ },
797
+ ],
798
+ };
799
+
800
+ expect(
801
+ await Promise.all(
802
+ createNodes(schema, "response").map(
803
+ async (md: any) => await prettier.format(md, { parser: "babel" })
804
+ )
805
+ )
806
+ ).toMatchSnapshot();
807
+ });
808
+
809
+ it("should handle basic discriminator with mapping", async () => {
810
+ const schema: SchemaObject = {
811
+ type: "object",
812
+ discriminator: {
813
+ propertyName: "type",
814
+ mapping: {
815
+ typeA: "#/definitions/TypeA",
816
+ typeB: "#/definitions/TypeB",
817
+ },
818
+ },
819
+ properties: {
820
+ type: { type: "string" },
821
+ },
822
+ oneOf: [
823
+ {
824
+ type: "object",
825
+ properties: {
826
+ type: { type: "string", enum: ["typeA"] },
827
+ propA: { type: "string" },
828
+ },
829
+ required: ["type"],
830
+ },
831
+ {
832
+ type: "object",
833
+ properties: {
834
+ type: { type: "string", enum: ["typeB"] },
835
+ propB: { type: "number" },
836
+ },
837
+ required: ["type"],
838
+ },
839
+ ],
840
+ };
841
+
842
+ expect(
843
+ await Promise.all(
844
+ createNodes(schema, "response").map(
845
+ async (md: any) => await prettier.format(md, { parser: "babel" })
846
+ )
847
+ )
848
+ ).toMatchSnapshot();
849
+ });
850
+
851
+ it("should handle discriminator with shared properties and mapping", async () => {
852
+ const schema: SchemaObject = {
853
+ type: "object",
854
+ discriminator: {
855
+ propertyName: "type",
856
+ mapping: {
857
+ typeA: "#/definitions/TypeA",
858
+ typeB: "#/definitions/TypeB",
859
+ },
860
+ },
861
+ properties: {
862
+ type: { type: "string" },
863
+ sharedProp: { type: "string" },
864
+ },
865
+ oneOf: [
866
+ {
867
+ type: "object",
868
+ properties: {
869
+ type: { type: "string", enum: ["typeA"] },
870
+ propA: { type: "string" },
871
+ },
872
+ required: ["type"],
873
+ },
874
+ {
875
+ type: "object",
876
+ properties: {
877
+ type: { type: "string", enum: ["typeB"] },
878
+ propB: { type: "number" },
879
+ },
880
+ required: ["type"],
881
+ },
882
+ ],
883
+ };
884
+
885
+ expect(
886
+ await Promise.all(
887
+ createNodes(schema, "response").map(
888
+ async (md: any) => await prettier.format(md, { parser: "babel" })
889
+ )
890
+ )
891
+ ).toMatchSnapshot();
892
+ });
893
+
894
+ it("should handle discriminator with allOf and mapping", async () => {
895
+ const schema: SchemaObject = {
896
+ type: "object",
897
+ discriminator: {
898
+ propertyName: "type",
899
+ mapping: {
900
+ typeA: "#/definitions/TypeA",
901
+ typeB: "#/definitions/TypeB",
902
+ },
903
+ },
904
+ properties: {
905
+ type: { type: "string" },
906
+ },
907
+ allOf: [
908
+ {
909
+ oneOf: [
910
+ {
911
+ type: "object",
912
+ properties: {
913
+ type: { type: "string", enum: ["typeA"] },
914
+ propA: { type: "string" },
915
+ },
916
+ required: ["type"],
917
+ },
918
+ {
919
+ type: "object",
920
+ properties: {
921
+ type: { type: "string", enum: ["typeB"] },
922
+ propB: { type: "number" },
923
+ },
924
+ required: ["type"],
925
+ },
926
+ ],
927
+ },
928
+ {
929
+ type: "object",
930
+ properties: {
931
+ sharedProp: { type: "string" },
932
+ },
933
+ },
934
+ ],
935
+ };
936
+
937
+ expect(
938
+ await Promise.all(
939
+ createNodes(schema, "response").map(
940
+ async (md: any) => await prettier.format(md, { parser: "babel" })
941
+ )
942
+ )
943
+ ).toMatchSnapshot();
944
+ });
945
+
946
+ it("should handle discriminator with required properties and mapping", async () => {
947
+ const schema: SchemaObject = {
948
+ type: "object",
949
+ discriminator: {
950
+ propertyName: "type",
951
+ mapping: {
952
+ typeA: "#/definitions/TypeA",
953
+ typeB: "#/definitions/TypeB",
954
+ },
955
+ },
956
+ properties: {
957
+ type: { type: "string" },
958
+ },
959
+ oneOf: [
960
+ {
961
+ type: "object",
962
+ properties: {
963
+ type: { type: "string", enum: ["typeA"] },
964
+ propA: { type: "string" },
965
+ },
966
+ required: ["type", "propA"],
967
+ },
968
+ {
969
+ type: "object",
970
+ properties: {
971
+ type: { type: "string", enum: ["typeB"] },
972
+ propB: { type: "number" },
973
+ },
974
+ required: ["type", "propB"],
975
+ },
976
+ ],
977
+ };
978
+
979
+ expect(
980
+ await Promise.all(
981
+ createNodes(schema, "response").map(
982
+ async (md: any) => await prettier.format(md, { parser: "babel" })
983
+ )
984
+ )
985
+ ).toMatchSnapshot();
986
+ });
987
+ });
988
+
316
989
  describe("additionalProperties", () => {
317
990
  it.each([
318
991
  [