@@ -84,7 +84,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
84
84
xmlRequestAndResponseBodyArrayTypeNoPrefix =
85
85
path . join ( __dirname , VALID_OPENAPI_PATH , '/xmlRequestAndResponseBodyArrayTypeNoPrefix.json' ) ,
86
86
xmlRequestAndResponseBodyArrayTypeWrapped =
87
- 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' ) ;
88
90
89
91
90
92
it ( 'Should add collection level auth with type as `bearer`' +
@@ -1568,33 +1570,6 @@ describe('CONVERT FUNCTION TESTS ', function() {
1568
1570
} ) ;
1569
1571
} ) ;
1570
1572
1571
- it ( 'Should fake correctly the body when schema has array type and additionalProperties' , function ( done ) {
1572
- var openapi = fs . readFileSync ( schemaWithArrayTypeAndAdditionalProperties , 'utf8' ) ;
1573
- Converter . convert ( { type : 'string' , data : openapi } , { schemaFaker : true } , ( err , conversionResult ) => {
1574
- const resultantResponseBody = JSON . parse (
1575
- conversionResult . output [ 0 ] . data . item [ 0 ] . response [ 0 ] . body
1576
- ) ,
1577
- resultantRequestBody = JSON . parse (
1578
- conversionResult . output [ 0 ] . data . item [ 0 ] . request . body . raw
1579
- ) ;
1580
- expect ( err ) . to . be . null ;
1581
- expect ( conversionResult . result ) . to . equal ( true ) ;
1582
- expect ( conversionResult . output . length ) . to . equal ( 1 ) ;
1583
- expect ( conversionResult . output [ 0 ] . type ) . to . equal ( 'collection' ) ;
1584
- expect ( conversionResult . output [ 0 ] . data ) . to . have . property ( 'info' ) ;
1585
- expect ( conversionResult . output [ 0 ] . data ) . to . have . property ( 'item' ) ;
1586
- expect ( resultantResponseBody . result ) . to . be . an ( 'array' )
1587
- . with . length ( 2 ) ;
1588
- expect ( resultantResponseBody . result [ 0 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1589
- expect ( resultantResponseBody . result [ 1 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1590
- expect ( resultantRequestBody . result ) . to . be . an ( 'array' )
1591
- . with . length ( 2 ) ;
1592
- expect ( resultantRequestBody . result [ 0 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1593
- expect ( resultantRequestBody . result [ 1 ] ) . to . include . all . keys ( 'id' , 'name' ) ;
1594
- done ( ) ;
1595
- } ) ;
1596
- } ) ;
1597
-
1598
1573
it ( 'Should convert and resolve xml bodies correctly when prefix is provided' , function ( done ) {
1599
1574
var openapi = fs . readFileSync ( xmlRequestAndResponseBody , 'utf8' ) ;
1600
1575
Converter . convert (
@@ -1775,6 +1750,74 @@ describe('CONVERT FUNCTION TESTS ', function() {
1775
1750
}
1776
1751
) ;
1777
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
+ } ) ;
1778
1821
} ) ;
1779
1822
1780
1823
describe ( 'Converting swagger 2.0 files' , function ( ) {
0 commit comments