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

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",
@@ -434,6 +434,348 @@ describe("createNodes", () => {
434
434
  // ).toMatchSnapshot();
435
435
  // });
436
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
+ });
437
779
  describe("additionalProperties", () => {
438
780
  it.each([
439
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": "0.0.0-765",
4
+ "version": "0.0.0-771",
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": "5d2e2e532fdd134faea5e0614b9a418f6bf9f20f"
65
+ "gitHead": "bd816ccb53e227f1626e85e0eedfb83fdaba7e87"
66
66
  }