docusaurus-plugin-openapi-docs 0.0.0-764 → 0.0.0-765

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.
@@ -72,6 +72,151 @@ 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
+ });
75
220
  });
76
221
  describe("allOf", () => {
77
222
  it("should render same-level properties with allOf", async () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "0.0.0-764",
4
+ "version": "0.0.0-765",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "77f469333fe35e210b049ee703f0db90c75e8989"
65
+ "gitHead": "5d2e2e532fdd134faea5e0614b9a418f6bf9f20f"
66
66
  }
@@ -457,3 +457,275 @@ Array [
457
457
  ",
458
458
  ]
459
459
  `;
460
+
461
+ exports[`createNodes oneOf should handle nested oneOf clauses 1`] = `
462
+ Array [
463
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
464
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
465
+ <summary style={{}}>
466
+ <span className={\\"openapi-schema__container\\"}>
467
+ <strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
468
+ <span className={\\"openapi-schema__name\\"}>object</span>
469
+ </span>
470
+ </summary>
471
+ <div style={{ marginLeft: \\"1rem\\" }}>
472
+ <div>
473
+ <span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
474
+ oneOf
475
+ </span>
476
+ <SchemaTabs>
477
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
478
+ <SchemaItem collapsible={true} className={\\"schemaItem\\"}>
479
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
480
+ <summary style={{}}>
481
+ <span className={\\"openapi-schema__container\\"}>
482
+ <strong className={\\"openapi-schema__property\\"}>
483
+ nestedOneOfProp
484
+ </strong>
485
+ <span className={\\"openapi-schema__name\\"}>object</span>
486
+ </span>
487
+ </summary>
488
+ <div style={{ marginLeft: \\"1rem\\" }}>
489
+ <div>
490
+ <span
491
+ className={\\"badge badge--info\\"}
492
+ style={{ marginBottom: \\"1rem\\" }}
493
+ >
494
+ oneOf
495
+ </span>
496
+ <SchemaTabs>
497
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
498
+ <div
499
+ style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}
500
+ >
501
+ string
502
+ </div>
503
+ </TabItem>
504
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
505
+ <div
506
+ style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}
507
+ >
508
+ number
509
+ </div>
510
+ </TabItem>
511
+ </SchemaTabs>
512
+ </div>
513
+ </div>
514
+ </details>
515
+ </SchemaItem>
516
+ </TabItem>
517
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
518
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
519
+ boolean
520
+ </div>
521
+ </TabItem>
522
+ </SchemaTabs>
523
+ </div>
524
+ </div>
525
+ </details>
526
+ </SchemaItem>;
527
+ ",
528
+ ]
529
+ `;
530
+
531
+ exports[`createNodes oneOf should handle oneOf with complex types 1`] = `
532
+ Array [
533
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
534
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
535
+ <summary style={{}}>
536
+ <span className={\\"openapi-schema__container\\"}>
537
+ <strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
538
+ <span className={\\"openapi-schema__name\\"}>object</span>
539
+ </span>
540
+ </summary>
541
+ <div style={{ marginLeft: \\"1rem\\" }}>
542
+ <div>
543
+ <span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
544
+ oneOf
545
+ </span>
546
+ <SchemaTabs>
547
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
548
+ <SchemaItem
549
+ collapsible={false}
550
+ name={\\"objectProp\\"}
551
+ required={false}
552
+ schemaName={\\"string\\"}
553
+ qualifierMessage={undefined}
554
+ schema={{ type: \\"string\\" }}
555
+ ></SchemaItem>
556
+ </TabItem>
557
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
558
+ <li>
559
+ <div
560
+ style={{
561
+ fontSize: \\"var(--ifm-code-font-size)\\",
562
+ opacity: \\"0.6\\",
563
+ marginLeft: \\"-.5rem\\",
564
+ paddingBottom: \\".5rem\\",
565
+ }}
566
+ >
567
+ Array [
568
+ </div>
569
+ </li>
570
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
571
+ number
572
+ </div>
573
+ <li>
574
+ <div
575
+ style={{
576
+ fontSize: \\"var(--ifm-code-font-size)\\",
577
+ opacity: \\"0.6\\",
578
+ marginLeft: \\"-.5rem\\",
579
+ }}
580
+ >
581
+ ]
582
+ </div>
583
+ </li>
584
+ </TabItem>
585
+ </SchemaTabs>
586
+ </div>
587
+ </div>
588
+ </details>
589
+ </SchemaItem>;
590
+ ",
591
+ ]
592
+ `;
593
+
594
+ exports[`createNodes oneOf should handle oneOf with different primitive types 1`] = `
595
+ Array [
596
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
597
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
598
+ <summary style={{}}>
599
+ <span className={\\"openapi-schema__container\\"}>
600
+ <strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
601
+ <span className={\\"openapi-schema__name\\"}>object</span>
602
+ </span>
603
+ </summary>
604
+ <div style={{ marginLeft: \\"1rem\\" }}>
605
+ <div>
606
+ <span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
607
+ oneOf
608
+ </span>
609
+ <SchemaTabs>
610
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
611
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
612
+ string
613
+ </div>
614
+ </TabItem>
615
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
616
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
617
+ number
618
+ </div>
619
+ </TabItem>
620
+ <TabItem label={\\"MOD3\\"} value={\\"2-item-properties\\"}>
621
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
622
+ boolean
623
+ </div>
624
+ </TabItem>
625
+ </SchemaTabs>
626
+ </div>
627
+ </div>
628
+ </details>
629
+ </SchemaItem>;
630
+ ",
631
+ ]
632
+ `;
633
+
634
+ exports[`createNodes oneOf should handle oneOf with required properties 1`] = `
635
+ Array [
636
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
637
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
638
+ <summary style={{}}>
639
+ <span className={\\"openapi-schema__container\\"}>
640
+ <strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
641
+ <span className={\\"openapi-schema__name\\"}>object</span>
642
+ </span>
643
+ </summary>
644
+ <div style={{ marginLeft: \\"1rem\\" }}>
645
+ <div>
646
+ <span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
647
+ oneOf
648
+ </span>
649
+ <SchemaTabs>
650
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
651
+ <SchemaItem
652
+ collapsible={false}
653
+ name={\\"requiredPropA\\"}
654
+ required={true}
655
+ schemaName={\\"string\\"}
656
+ qualifierMessage={undefined}
657
+ schema={{ type: \\"string\\" }}
658
+ ></SchemaItem>
659
+ </TabItem>
660
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
661
+ <SchemaItem
662
+ collapsible={false}
663
+ name={\\"requiredPropB\\"}
664
+ required={true}
665
+ schemaName={\\"number\\"}
666
+ qualifierMessage={undefined}
667
+ schema={{ type: \\"number\\" }}
668
+ ></SchemaItem>
669
+ </TabItem>
670
+ </SchemaTabs>
671
+ </div>
672
+ </div>
673
+ </details>
674
+ </SchemaItem>;
675
+ ",
676
+ ]
677
+ `;
678
+
679
+ exports[`createNodes oneOf should handle oneOf with shared properties 1`] = `
680
+ Array [
681
+ "<SchemaItem
682
+ collapsible={false}
683
+ name={\\"sharedProp\\"}
684
+ required={false}
685
+ schemaName={\\"string\\"}
686
+ qualifierMessage={undefined}
687
+ schema={{ type: \\"string\\" }}
688
+ ></SchemaItem>;
689
+ ",
690
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
691
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
692
+ <summary style={{}}>
693
+ <span className={\\"openapi-schema__container\\"}>
694
+ <strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
695
+ <span className={\\"openapi-schema__name\\"}>object</span>
696
+ </span>
697
+ </summary>
698
+ <div style={{ marginLeft: \\"1rem\\" }}>
699
+ <div>
700
+ <span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
701
+ oneOf
702
+ </span>
703
+ <SchemaTabs>
704
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
705
+ <SchemaItem
706
+ collapsible={false}
707
+ name={\\"specificPropA\\"}
708
+ required={false}
709
+ schemaName={\\"string\\"}
710
+ qualifierMessage={undefined}
711
+ schema={{ type: \\"string\\" }}
712
+ ></SchemaItem>
713
+ </TabItem>
714
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
715
+ <SchemaItem
716
+ collapsible={false}
717
+ name={\\"specificPropB\\"}
718
+ required={false}
719
+ schemaName={\\"number\\"}
720
+ qualifierMessage={undefined}
721
+ schema={{ type: \\"number\\" }}
722
+ ></SchemaItem>
723
+ </TabItem>
724
+ </SchemaTabs>
725
+ </div>
726
+ </div>
727
+ </details>
728
+ </SchemaItem>;
729
+ ",
730
+ ]
731
+ `;
@@ -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", () => {