@@ -56,6 +56,8 @@ const listOfBannedSchemas = require("../schemas/SchemasThatCannotBeConverted/lis
56
56
// anyOf/oneOf Nulls
57
57
const oneOfNull = require ( "../schemas/ofNulls/oneOfNull.json" ) ;
58
58
const anyOfNull = require ( "../schemas/ofNulls/anyOfNull.json" ) ;
59
+ const moreThanoneOfNull = require ( "../schemas/ofNulls/moreThanOneoneOf.json" ) ;
60
+ const moreThananyOfNull = require ( "../schemas/ofNulls/moreThanOneanyOf.json" ) ;
59
61
// anyOf/oneOf Nulls
60
62
const allOfProperties = require ( "../schemas/propertiesOutsideOf/allOf.json" ) ;
61
63
const oneOfProperties = require ( "../schemas/propertiesOutsideOf/oneOf.json" ) ;
@@ -712,13 +714,18 @@ describe("Convertor", () => {
712
714
it ( "should convert an anyOf with a type of null" , async function ( ) {
713
715
const newConvertor = new Convertor ( anyOfNull ) ;
714
716
const result = newConvertor . convert ( "basic" ) ;
715
- expect ( result . schemas . basic . properties . payment ) . to . have . property (
717
+
718
+ expect ( result . schemas . basic . properties . payment ) . to . not . have . property (
716
719
"anyOf"
717
720
) ;
718
- expect ( result . schemas . basic . properties . payment . anyOf ) . to . be . an ( "array" ) ;
719
- expect (
720
- result . schemas . basic . properties . payment . anyOf . length
721
- ) . to . be . equal ( 1 ) ;
721
+ expect ( result . schemas . basic . properties . payment ) . to . have . property (
722
+ "type" ,
723
+ "string"
724
+ ) ;
725
+ expect ( result . schemas . basic . properties . payment ) . to . have . property (
726
+ "nullable" ,
727
+ true
728
+ ) ;
722
729
723
730
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
724
731
Object . assign ( cloned , { components : result } ) ;
@@ -732,13 +739,78 @@ describe("Convertor", () => {
732
739
it ( "should convert a oneOf with a type of null" , async function ( ) {
733
740
const newConvertor = new Convertor ( oneOfNull ) ;
734
741
const result = newConvertor . convert ( "basic" ) ;
742
+ expect ( result . schemas . basic . properties . payment ) . to . not . have . property (
743
+ "oneOf"
744
+ ) ;
745
+ expect ( result . schemas . basic . properties . payment ) . to . have . property (
746
+ "type" ,
747
+ "string"
748
+ ) ;
749
+ expect ( result . schemas . basic . properties . payment ) . to . have . property (
750
+ "nullable" ,
751
+ true
752
+ ) ;
753
+
754
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
755
+ Object . assign ( cloned , { components : result } ) ;
756
+ expect ( cloned ) . to . have . property ( "components" ) ;
757
+ expect ( cloned . components ) . to . have . property ( "schemas" ) ;
758
+ expect ( cloned . components . schemas ) . to . have . property ( "basic" ) ;
759
+ let valid = await validator . validateInner ( cloned , { } ) ;
760
+ expect ( valid ) . to . be . true ;
761
+ } ) ;
762
+
763
+ it ( "should convert an anyOf with a type of null and more than one non null type" , async function ( ) {
764
+ const newConvertor = new Convertor ( moreThananyOfNull ) ;
765
+ const result = newConvertor . convert ( "basic" ) ;
766
+
767
+ expect ( result . schemas . basic . properties . payment ) . to . have . property (
768
+ "anyOf"
769
+ ) ;
770
+ expect ( result . schemas . basic . properties . payment . anyOf ) . to . have . lengthOf (
771
+ 2
772
+ ) ;
773
+ const stringAnyOf =
774
+ result . schemas . basic . properties . payment . anyOf . filter (
775
+ ( schema ) => schema . type === "string"
776
+ ) ;
777
+ expect ( stringAnyOf [ 0 ] ) . to . have . property ( "nullable" , true ) ;
778
+
779
+ const integerAnyOf =
780
+ result . schemas . basic . properties . payment . anyOf . filter (
781
+ ( schema ) => schema . type === "integer"
782
+ ) ;
783
+ expect ( integerAnyOf [ 0 ] ) . to . have . property ( "nullable" , true ) ;
784
+
785
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
786
+ Object . assign ( cloned , { components : result } ) ;
787
+ expect ( cloned ) . to . have . property ( "components" ) ;
788
+ expect ( cloned . components ) . to . have . property ( "schemas" ) ;
789
+ expect ( cloned . components . schemas ) . to . have . property ( "basic" ) ;
790
+ let valid = await validator . validateInner ( cloned , { } ) ;
791
+ expect ( valid ) . to . be . true ;
792
+ } ) ;
793
+
794
+ it ( "should convert a oneOf with a type of null and more than one non null type" , async function ( ) {
795
+ const newConvertor = new Convertor ( moreThanoneOfNull ) ;
796
+ const result = newConvertor . convert ( "basic" ) ;
735
797
expect ( result . schemas . basic . properties . payment ) . to . have . property (
736
798
"oneOf"
737
799
) ;
738
- expect ( result . schemas . basic . properties . payment . oneOf ) . to . be . an ( "array" ) ;
739
- expect (
740
- result . schemas . basic . properties . payment . oneOf . length
741
- ) . to . be . equal ( 1 ) ;
800
+ expect ( result . schemas . basic . properties . payment . oneOf ) . to . have . lengthOf (
801
+ 2
802
+ ) ;
803
+ const stringOneOf =
804
+ result . schemas . basic . properties . payment . oneOf . filter (
805
+ ( schema ) => schema . type === "string"
806
+ ) ;
807
+ expect ( stringOneOf [ 0 ] ) . to . have . property ( "nullable" , true ) ;
808
+
809
+ const booleanOneOf =
810
+ result . schemas . basic . properties . payment . oneOf . filter (
811
+ ( schema ) => schema . type === "boolean"
812
+ ) ;
813
+ expect ( booleanOneOf [ 0 ] ) . to . have . property ( "nullable" , true ) ;
742
814
743
815
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
744
816
Object . assign ( cloned , { components : result } ) ;
0 commit comments