@@ -1714,3 +1714,183 @@ describe('validateTransaction convert and validate schemas with allOf', function
1714
1714
} ) ;
1715
1715
} ) ;
1716
1716
1717
+ describe ( 'validateTransaction convert and validate schemas with deprecated elements' , function ( ) {
1718
+ it ( 'Should convert and validate and include deprecated operation default option' , function ( ) {
1719
+ const openAPI = path . join ( __dirname , VALID_OPENAPI_FOLDER_PATH + '/has_some_op_dep.json' ) ,
1720
+ openAPIData = fs . readFileSync ( openAPI , 'utf8' ) ,
1721
+ options = {
1722
+ showMissingInSchemaErrors : true ,
1723
+ strictRequestMatching : true ,
1724
+ ignoreUnresolvedVariables : true
1725
+ } ,
1726
+ schemaPack = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , options ) ;
1727
+ schemaPack . convert ( ( err , conversionResult ) => {
1728
+ expect ( err ) . to . be . null ;
1729
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1730
+ expect ( conversionResult . output [ 0 ] . data . item . length ) . to . equal ( 1 ) ;
1731
+
1732
+ let historyRequest = [ ] ;
1733
+
1734
+ getAllTransactions ( conversionResult . output [ 0 ] . data , historyRequest ) ;
1735
+
1736
+ schemaPack . validateTransaction ( historyRequest , ( err , result ) => {
1737
+ expect ( err ) . to . be . null ;
1738
+ expect ( result ) . to . be . an ( 'object' ) ;
1739
+
1740
+ expect ( err ) . to . be . null ;
1741
+ expect ( result . missingEndpoints . length ) . to . eq ( 0 ) ;
1742
+
1743
+ let requestIds = Object . keys ( result . requests ) ;
1744
+ requestIds . forEach ( ( requestId ) => {
1745
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] ) . to . not . be . undefined ;
1746
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] . matched ) . to . be . true ;
1747
+ } ) ;
1748
+ } ) ;
1749
+ } ) ;
1750
+ } ) ;
1751
+
1752
+ it ( 'Should convert and validate and include deprecated operation' , function ( ) {
1753
+ const openAPI = path . join ( __dirname , VALID_OPENAPI_FOLDER_PATH + '/has_some_op_dep.json' ) ,
1754
+ openAPIData = fs . readFileSync ( openAPI , 'utf8' ) ,
1755
+ options = {
1756
+ showMissingInSchemaErrors : true ,
1757
+ strictRequestMatching : true ,
1758
+ ignoreUnresolvedVariables : true ,
1759
+ includeDeprecated : true
1760
+ } ,
1761
+ schemaPack = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , options ) ;
1762
+ schemaPack . convert ( ( err , conversionResult ) => {
1763
+ expect ( err ) . to . be . null ;
1764
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1765
+ expect ( conversionResult . output [ 0 ] . data . item . length ) . to . equal ( 1 ) ;
1766
+
1767
+ let historyRequest = [ ] ;
1768
+
1769
+ getAllTransactions ( conversionResult . output [ 0 ] . data , historyRequest ) ;
1770
+
1771
+ schemaPack . validateTransaction ( historyRequest , ( err , result ) => {
1772
+ expect ( err ) . to . be . null ;
1773
+ expect ( result ) . to . be . an ( 'object' ) ;
1774
+
1775
+ expect ( err ) . to . be . null ;
1776
+ expect ( result . missingEndpoints . length ) . to . eq ( 0 ) ;
1777
+
1778
+ let requestIds = Object . keys ( result . requests ) ;
1779
+ requestIds . forEach ( ( requestId ) => {
1780
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] ) . to . not . be . undefined ;
1781
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] . matched ) . to . be . true ;
1782
+ } ) ;
1783
+ } ) ;
1784
+ } ) ;
1785
+ } ) ;
1786
+
1787
+ it ( 'Should convert and validate not including deprecated operation and no missing endpoint' , function ( ) {
1788
+ const openAPI = path . join ( __dirname , VALID_OPENAPI_FOLDER_PATH + '/has_some_op_dep.json' ) ,
1789
+ openAPIData = fs . readFileSync ( openAPI , 'utf8' ) ,
1790
+ options = {
1791
+ showMissingInSchemaErrors : true ,
1792
+ strictRequestMatching : true ,
1793
+ ignoreUnresolvedVariables : true ,
1794
+ includeDeprecated : false
1795
+ } ,
1796
+ schemaPack = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , options ) ;
1797
+ schemaPack . convert ( ( err , conversionResult ) => {
1798
+ expect ( err ) . to . be . null ;
1799
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1800
+ expect ( conversionResult . output [ 0 ] . data . item . length ) . to . equal ( 1 ) ;
1801
+
1802
+ let historyRequest = [ ] ;
1803
+
1804
+ getAllTransactions ( conversionResult . output [ 0 ] . data , historyRequest ) ;
1805
+
1806
+ schemaPack . validateTransaction ( historyRequest , ( err , result ) => {
1807
+ expect ( err ) . to . be . null ;
1808
+ expect ( result ) . to . be . an ( 'object' ) ;
1809
+
1810
+ expect ( err ) . to . be . null ;
1811
+ expect ( result . missingEndpoints . length ) . to . eq ( 0 ) ;
1812
+ let requestIds = Object . keys ( result . requests ) ;
1813
+ requestIds . forEach ( ( requestId ) => {
1814
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] ) . to . not . be . undefined ;
1815
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] . matched ) . to . be . true ;
1816
+ } ) ;
1817
+ } ) ;
1818
+ } ) ;
1819
+ } ) ;
1820
+
1821
+ it ( 'Should convert and validate including deprecated operation and report mismatch' +
1822
+ 'when missing' , function ( ) {
1823
+ const openAPI = path . join ( __dirname , VALID_OPENAPI_FOLDER_PATH + '/has_some_op_dep.json' ) ,
1824
+ openAPIData = fs . readFileSync ( openAPI , 'utf8' ) ,
1825
+ options = {
1826
+ showMissingInSchemaErrors : true ,
1827
+ strictRequestMatching : true ,
1828
+ ignoreUnresolvedVariables : true ,
1829
+ includeDeprecated : true
1830
+ } ,
1831
+ schemaPack = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , options ) ;
1832
+ schemaPack . convert ( ( err , conversionResult ) => {
1833
+ expect ( err ) . to . be . null ;
1834
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1835
+ expect ( conversionResult . output [ 0 ] . data . item . length ) . to . equal ( 1 ) ;
1836
+
1837
+ let historyRequest = [ ] ;
1838
+
1839
+ getAllTransactions ( conversionResult . output [ 0 ] . data , historyRequest ) ;
1840
+
1841
+ historyRequest . shift ( ) ;
1842
+ schemaPack . validateTransaction ( historyRequest , ( err , result ) => {
1843
+ expect ( err ) . to . be . null ;
1844
+ expect ( result ) . to . be . an ( 'object' ) ;
1845
+
1846
+ expect ( err ) . to . be . null ;
1847
+ expect ( result . missingEndpoints . length ) . to . eq ( 1 ) ;
1848
+ expect ( result . missingEndpoints [ 0 ] . endpoint ) . to . eq ( 'GET /pets' ) ;
1849
+ let requestIds = Object . keys ( result . requests ) ;
1850
+ requestIds . forEach ( ( requestId ) => {
1851
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] ) . to . not . be . undefined ;
1852
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] . matched ) . to . be . true ;
1853
+ } ) ;
1854
+ } ) ;
1855
+ } ) ;
1856
+ } ) ;
1857
+
1858
+ it ( 'Should convert and validate including deprecated operation and validate when deprecated is present' , function ( ) {
1859
+ const openAPI = path . join ( __dirname , VALID_OPENAPI_FOLDER_PATH + '/has_some_op_dep.json' ) ,
1860
+ openAPIData = fs . readFileSync ( openAPI , 'utf8' ) ,
1861
+ options = {
1862
+ showMissingInSchemaErrors : true ,
1863
+ strictRequestMatching : true ,
1864
+ ignoreUnresolvedVariables : true ,
1865
+ includeDeprecated : true
1866
+ } ,
1867
+ schemaPack = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , options ) ;
1868
+ schemaPack . convert ( ( err , conversionResult ) => {
1869
+ expect ( err ) . to . be . null ;
1870
+ expect ( conversionResult . result ) . to . equal ( true ) ;
1871
+
1872
+ let historyRequest = [ ] ,
1873
+ optionsOtherSchemaPack = {
1874
+ showMissingInSchemaErrors : true ,
1875
+ strictRequestMatching : true ,
1876
+ ignoreUnresolvedVariables : true ,
1877
+ includeDeprecated : false
1878
+ } ,
1879
+ schemaPack2 = new Converter . SchemaPack ( { type : 'string' , data : openAPIData } , optionsOtherSchemaPack ) ;
1880
+
1881
+ getAllTransactions ( conversionResult . output [ 0 ] . data , historyRequest ) ;
1882
+
1883
+ schemaPack2 . validateTransaction ( historyRequest , ( err , result ) => {
1884
+ expect ( err ) . to . be . null ;
1885
+ expect ( result ) . to . be . an ( 'object' ) ;
1886
+
1887
+ expect ( err ) . to . be . null ;
1888
+ let requestIds = Object . keys ( result . requests ) ;
1889
+ requestIds . forEach ( ( requestId ) => {
1890
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] ) . to . not . be . undefined ;
1891
+ expect ( result . requests [ requestId ] . endpoints [ 0 ] . matched ) . to . be . true ;
1892
+ } ) ;
1893
+ } ) ;
1894
+ } ) ;
1895
+ } ) ;
1896
+ } ) ;
0 commit comments