@@ -74,6 +74,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
74
74
specWithAuthDigest = path . join ( __dirname , VALID_OPENAPI_PATH + '/specWithAuthDigest.yaml' ) ,
75
75
specWithAuthOauth1 = path . join ( __dirname , VALID_OPENAPI_PATH + '/specWithAuthOauth1.yaml' ) ,
76
76
specWithAuthBasic = path . join ( __dirname , VALID_OPENAPI_PATH + '/specWithAuthBasic.yaml' ) ,
77
+ schemaWithArrayTypeAndAdditionalProperties =
78
+ path . join ( __dirname , VALID_OPENAPI_PATH + '/schemaWithArrayTypeAndAdditionalProperties.yaml' ) ,
77
79
xmlRequestAndResponseBody = path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBody.json' ) ,
78
80
xmlRequestAndResponseBodyNoPrefix =
79
81
path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBodyNoPrefix.json' ) ,
@@ -82,7 +84,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
82
84
xmlRequestAndResponseBodyArrayTypeNoPrefix =
83
85
path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBodyArrayTypeNoPrefix.json' ) ,
84
86
xmlRequestAndResponseBodyArrayTypeWrapped =
85
- path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBodyArrayTypeWrapped.json' ) ;
87
+ path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBodyArrayTypeWrapped.json' ) ,
88
+ schemaWithAdditionalProperties =
89
+ path . join ( __dirname , VALID_OPENAPI_PATH , '/schemaWithAdditionalProperties.yaml' ) ;
86
90
87
91
88
92
it ( 'Should add collection level auth with type as `bearer`' +
@@ -1746,6 +1750,74 @@ describe('CONVERT FUNCTION TESTS ', function() {
1746
1750
}
1747
1751
) ;
1748
1752
} ) ;
1753
+
1754
+ it ( 'Should fake correctly the body when schema has array type and additionalProperties' , function ( done ) {
1755
+ var openapi = fs . readFileSync ( schemaWithArrayTypeAndAdditionalProperties , 'utf8' ) ;
1756
+ Converter . convert ( { type : 'string' , data : openapi } , { schemaFaker : true } , ( err , conversionResult ) => {
1757
+ const resultantResponseBody = JSON . parse (
1758
+ conversionResult . output [ 0 ] . data . item [ 0 ] . response [ 0 ] . body
1759
+ ) ,
1760
+ resultantRequestBody = JSON . parse (
1761
+ conversionResult . output [ 0 ] . data . item [ 0 ] . request . body . raw
1762
+ ) ;
1763
+ expect ( err ) . to . be . null ;
1764
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1765
+ expect ( conversionResult . output . length ) . to . equal ( 1 ) ;
1766
+ expect ( conversionResult . output [ 0 ] . type ) . to . equal ( 'collection' ) ;
1767
+ expect ( conversionResult . output [ 0 ] . data ) . to . have . property ( 'info' ) ;
1768
+ expect ( conversionResult . output [ 0 ] . data ) . to . have . property ( 'item' ) ;
1769
+ expect ( resultantResponseBody . result ) . to . be . an ( 'array' )
1770
+ . with . length ( 2 ) ;
1771
+ expect ( resultantResponseBody . result [ 0 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1772
+ expect ( resultantResponseBody . result [ 1 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1773
+ expect ( resultantRequestBody . result ) . to . be . an ( 'array' )
1774
+ . with . length ( 2 ) ;
1775
+ expect ( resultantRequestBody . result [ 0 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1776
+ expect ( resultantRequestBody . result [ 1 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1777
+ done ( ) ;
1778
+ } ) ;
1779
+ } ) ;
1780
+
1781
+ it ( 'Should resolve correctly schemas with additionalProperties as false' , function ( done ) {
1782
+ var openapi = fs . readFileSync ( schemaWithAdditionalProperties , 'utf8' ) ;
1783
+ Converter . convert (
1784
+ { type : 'string' , data : openapi } ,
1785
+ { schemaFaker : true } ,
1786
+ ( err , conversionResult ) => {
1787
+ const requestBodyWithAdditionalPropertiesAsFalse =
1788
+ JSON . parse ( conversionResult . output [ 0 ] . data . item [ 0 ] . request . body . raw ) ;
1789
+ expect ( requestBodyWithAdditionalPropertiesAsFalse ) . to . include . keys ( 'test' ) ;
1790
+ expect ( Object . keys ( requestBodyWithAdditionalPropertiesAsFalse ) ) . to . have . length ( 1 ) ;
1791
+ done ( ) ;
1792
+ } ) ;
1793
+ } ) ;
1794
+
1795
+ it ( 'Should resolve correctly schemas with ONLY additionalProperties' , function ( done ) {
1796
+ var openapi = fs . readFileSync ( schemaWithAdditionalProperties , 'utf8' ) ;
1797
+ Converter . convert (
1798
+ { type : 'string' , data : openapi } ,
1799
+ { schemaFaker : true } ,
1800
+ ( err , conversionResult ) => {
1801
+ const responseBodyWithOnlyAdditionalProperties =
1802
+ JSON . parse ( conversionResult . output [ 0 ] . data . item [ 0 ] . response [ 0 ] . body ) ;
1803
+ expect ( Object . keys ( responseBodyWithOnlyAdditionalProperties ) . length ) . to . be . greaterThan ( 0 ) ;
1804
+ done ( ) ;
1805
+ } ) ;
1806
+ } ) ;
1807
+
1808
+ it ( 'Should resolve correctly schemas with additionalProperties' , function ( done ) {
1809
+ var openapi = fs . readFileSync ( schemaWithAdditionalProperties , 'utf8' ) ;
1810
+ Converter . convert (
1811
+ { type : 'string' , data : openapi } ,
1812
+ { schemaFaker : true } ,
1813
+ ( err , conversionResult ) => {
1814
+ const responseBodyWithAdditionalProperties =
1815
+ JSON . parse ( conversionResult . output [ 0 ] . data . item [ 0 ] . response [ 1 ] . body ) ;
1816
+ expect ( responseBodyWithAdditionalProperties ) . to . include . keys ( 'test1' ) ;
1817
+ expect ( Object . keys ( responseBodyWithAdditionalProperties ) . length ) . to . be . greaterThan ( 1 ) ;
1818
+ done ( ) ;
1819
+ } ) ;
1820
+ } ) ;
1749
1821
} ) ;
1750
1822
1751
1823
describe ( 'Converting swagger 2.0 files' , function ( ) {
0 commit comments