docusaurus-plugin-openapi-docs 4.0.0 → 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 CHANGED
@@ -41,9 +41,9 @@ Key Features:
41
41
 
42
42
  | Docusaurus OpenAPI Docs | Docusaurus |
43
43
  | ----------------------- | --------------- |
44
- | 4.0.0 (current) | `3.5.0 - 3.5.2` |
45
- | 3.0.2 (legacy) | `3.0.1 - 3.4.0` |
46
- | 2.2.1 (legacy) | `2.4.1 - 2.4.3` |
44
+ | 4.0.x (current) | `3.5.0 - 3.5.2` |
45
+ | 3.0.x (end-of-support) | `3.0.1 - 3.4.0` |
46
+ | 2.2.3 (legacy) | `2.4.1 - 2.4.3` |
47
47
  | 1.7.3 (end-of-support) | `2.0.1 - 2.2.0` |
48
48
 
49
49
  ## Bootstrapping from Template (new Docusaurus site)
@@ -447,8 +447,9 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
447
447
  if (schema === undefined) {
448
448
  return undefined;
449
449
  }
450
+ // render as a simple property if there's no mapping
450
451
  if (discriminator.mapping === undefined) {
451
- return undefined;
452
+ return createEdges({ name, schema, required });
452
453
  }
453
454
  return (0, utils_1.create)("div", {
454
455
  className: "openapi-discriminator__item openapi-schema__list-item",
@@ -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 () => {
@@ -289,6 +434,348 @@ describe("createNodes", () => {
289
434
  // ).toMatchSnapshot();
290
435
  // });
291
436
  });
437
+ describe("discriminator", () => {
438
+ it("should handle basic discriminator with oneOf", async () => {
439
+ const schema = {
440
+ type: "object",
441
+ discriminator: { propertyName: "type" },
442
+ properties: {
443
+ type: { type: "string" },
444
+ },
445
+ oneOf: [
446
+ {
447
+ type: "object",
448
+ properties: {
449
+ type: { type: "string", enum: ["typeA"] },
450
+ propA: { type: "string" },
451
+ },
452
+ required: ["type"],
453
+ },
454
+ {
455
+ type: "object",
456
+ properties: {
457
+ type: { type: "string", enum: ["typeB"] },
458
+ propB: { type: "number" },
459
+ },
460
+ required: ["type"],
461
+ },
462
+ ],
463
+ };
464
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
465
+ });
466
+ it("should handle discriminator with shared properties", async () => {
467
+ const schema = {
468
+ type: "object",
469
+ discriminator: { propertyName: "type" },
470
+ properties: {
471
+ type: { type: "string" },
472
+ sharedProp: { type: "string" },
473
+ },
474
+ oneOf: [
475
+ {
476
+ type: "object",
477
+ properties: {
478
+ type: { type: "string", enum: ["typeA"] },
479
+ propA: { type: "string" },
480
+ },
481
+ required: ["type"],
482
+ },
483
+ {
484
+ type: "object",
485
+ properties: {
486
+ type: { type: "string", enum: ["typeB"] },
487
+ propB: { type: "number" },
488
+ },
489
+ required: ["type"],
490
+ },
491
+ ],
492
+ };
493
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
494
+ });
495
+ it("should handle discriminator with nested schemas", async () => {
496
+ const schema = {
497
+ type: "object",
498
+ discriminator: { propertyName: "type" },
499
+ properties: {
500
+ type: { type: "string" },
501
+ },
502
+ oneOf: [
503
+ {
504
+ type: "object",
505
+ properties: {
506
+ type: { type: "string", enum: ["typeA"] },
507
+ nestedA: {
508
+ type: "object",
509
+ properties: {
510
+ propA1: { type: "string" },
511
+ propA2: { type: "number" },
512
+ },
513
+ },
514
+ },
515
+ required: ["type"],
516
+ },
517
+ {
518
+ type: "object",
519
+ properties: {
520
+ type: { type: "string", enum: ["typeB"] },
521
+ nestedB: {
522
+ type: "object",
523
+ properties: {
524
+ propB1: { type: "string" },
525
+ propB2: { type: "boolean" },
526
+ },
527
+ },
528
+ },
529
+ required: ["type"],
530
+ },
531
+ ],
532
+ };
533
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
534
+ });
535
+ it("should handle discriminator with additional properties", async () => {
536
+ const schema = {
537
+ type: "object",
538
+ discriminator: { propertyName: "type" },
539
+ properties: {
540
+ type: { type: "string" },
541
+ },
542
+ oneOf: [
543
+ {
544
+ type: "object",
545
+ properties: {
546
+ type: { type: "string", enum: ["typeA"] },
547
+ propA: { type: "string" },
548
+ },
549
+ additionalProperties: false,
550
+ required: ["type"],
551
+ },
552
+ {
553
+ type: "object",
554
+ properties: {
555
+ type: { type: "string", enum: ["typeB"] },
556
+ propB: { type: "number" },
557
+ },
558
+ additionalProperties: true,
559
+ required: ["type"],
560
+ },
561
+ ],
562
+ };
563
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
564
+ });
565
+ it("should handle discriminator with allOf", async () => {
566
+ const schema = {
567
+ type: "object",
568
+ discriminator: { propertyName: "type" },
569
+ properties: {
570
+ type: { type: "string" },
571
+ },
572
+ allOf: [
573
+ {
574
+ oneOf: [
575
+ {
576
+ type: "object",
577
+ properties: {
578
+ type: { type: "string", enum: ["typeA"] },
579
+ propA: { type: "string" },
580
+ },
581
+ required: ["type"],
582
+ },
583
+ {
584
+ type: "object",
585
+ properties: {
586
+ type: { type: "string", enum: ["typeB"] },
587
+ propB: { type: "number" },
588
+ },
589
+ required: ["type"],
590
+ },
591
+ ],
592
+ },
593
+ {
594
+ type: "object",
595
+ properties: {
596
+ sharedProp: { type: "string" },
597
+ },
598
+ },
599
+ ],
600
+ };
601
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
602
+ });
603
+ it("should handle discriminator with required properties", async () => {
604
+ const schema = {
605
+ type: "object",
606
+ discriminator: { propertyName: "type" },
607
+ properties: {
608
+ type: { type: "string" },
609
+ },
610
+ oneOf: [
611
+ {
612
+ type: "object",
613
+ properties: {
614
+ type: { type: "string", enum: ["typeA"] },
615
+ propA: { type: "string" },
616
+ },
617
+ required: ["type", "propA"],
618
+ },
619
+ {
620
+ type: "object",
621
+ properties: {
622
+ type: { type: "string", enum: ["typeB"] },
623
+ propB: { type: "number" },
624
+ },
625
+ required: ["type", "propB"],
626
+ },
627
+ ],
628
+ };
629
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
630
+ });
631
+ it("should handle basic discriminator with mapping", async () => {
632
+ const schema = {
633
+ type: "object",
634
+ discriminator: {
635
+ propertyName: "type",
636
+ mapping: {
637
+ typeA: "#/definitions/TypeA",
638
+ typeB: "#/definitions/TypeB",
639
+ },
640
+ },
641
+ properties: {
642
+ type: { type: "string" },
643
+ },
644
+ oneOf: [
645
+ {
646
+ type: "object",
647
+ properties: {
648
+ type: { type: "string", enum: ["typeA"] },
649
+ propA: { type: "string" },
650
+ },
651
+ required: ["type"],
652
+ },
653
+ {
654
+ type: "object",
655
+ properties: {
656
+ type: { type: "string", enum: ["typeB"] },
657
+ propB: { type: "number" },
658
+ },
659
+ required: ["type"],
660
+ },
661
+ ],
662
+ };
663
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
664
+ });
665
+ it("should handle discriminator with shared properties and mapping", async () => {
666
+ const schema = {
667
+ type: "object",
668
+ discriminator: {
669
+ propertyName: "type",
670
+ mapping: {
671
+ typeA: "#/definitions/TypeA",
672
+ typeB: "#/definitions/TypeB",
673
+ },
674
+ },
675
+ properties: {
676
+ type: { type: "string" },
677
+ sharedProp: { type: "string" },
678
+ },
679
+ oneOf: [
680
+ {
681
+ type: "object",
682
+ properties: {
683
+ type: { type: "string", enum: ["typeA"] },
684
+ propA: { type: "string" },
685
+ },
686
+ required: ["type"],
687
+ },
688
+ {
689
+ type: "object",
690
+ properties: {
691
+ type: { type: "string", enum: ["typeB"] },
692
+ propB: { type: "number" },
693
+ },
694
+ required: ["type"],
695
+ },
696
+ ],
697
+ };
698
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
699
+ });
700
+ it("should handle discriminator with allOf and mapping", async () => {
701
+ const schema = {
702
+ type: "object",
703
+ discriminator: {
704
+ propertyName: "type",
705
+ mapping: {
706
+ typeA: "#/definitions/TypeA",
707
+ typeB: "#/definitions/TypeB",
708
+ },
709
+ },
710
+ properties: {
711
+ type: { type: "string" },
712
+ },
713
+ allOf: [
714
+ {
715
+ oneOf: [
716
+ {
717
+ type: "object",
718
+ properties: {
719
+ type: { type: "string", enum: ["typeA"] },
720
+ propA: { type: "string" },
721
+ },
722
+ required: ["type"],
723
+ },
724
+ {
725
+ type: "object",
726
+ properties: {
727
+ type: { type: "string", enum: ["typeB"] },
728
+ propB: { type: "number" },
729
+ },
730
+ required: ["type"],
731
+ },
732
+ ],
733
+ },
734
+ {
735
+ type: "object",
736
+ properties: {
737
+ sharedProp: { type: "string" },
738
+ },
739
+ },
740
+ ],
741
+ };
742
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
743
+ });
744
+ it("should handle discriminator with required properties and mapping", async () => {
745
+ const schema = {
746
+ type: "object",
747
+ discriminator: {
748
+ propertyName: "type",
749
+ mapping: {
750
+ typeA: "#/definitions/TypeA",
751
+ typeB: "#/definitions/TypeB",
752
+ },
753
+ },
754
+ properties: {
755
+ type: { type: "string" },
756
+ },
757
+ oneOf: [
758
+ {
759
+ type: "object",
760
+ properties: {
761
+ type: { type: "string", enum: ["typeA"] },
762
+ propA: { type: "string" },
763
+ },
764
+ required: ["type", "propA"],
765
+ },
766
+ {
767
+ type: "object",
768
+ properties: {
769
+ type: { type: "string", enum: ["typeB"] },
770
+ propB: { type: "number" },
771
+ },
772
+ required: ["type", "propB"],
773
+ },
774
+ ],
775
+ };
776
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
777
+ });
778
+ });
292
779
  describe("additionalProperties", () => {
293
780
  it.each([
294
781
  [
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": "4.0.0",
4
+ "version": "4.0.1",
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": "79d74177cfd54d2750dde1e15c6ea166f9ca4be9"
65
+ "gitHead": "e228de93d24062c46fb206548dca7af9bc6264bb"
66
66
  }