2
2
* This file contains util functions that need OAS-awareness
3
3
* utils.js contains other util functions
4
4
*/
5
-
6
- const { ParseError } = require ( './common/ParseError.js' ) ;
7
-
8
5
const { formatDataPath, checkIsCorrectType, isKnownType } = require ( './common/schemaUtilsCommon.js' ) ,
9
6
{ getConcreteSchemaUtils, isSwagger, validateSupportedVersion } = require ( './common/versionUtils.js' ) ,
10
7
async = require ( 'async' ) ,
11
- sdk = require ( 'postman-collection' ) ,
8
+ { Variable } = require ( 'postman-collection/lib/collection/variable' ) ,
9
+ { QueryParam } = require ( 'postman-collection/lib/collection/query-param' ) ,
10
+ { Header } = require ( 'postman-collection/lib/collection/header' ) ,
11
+ { ItemGroup } = require ( 'postman-collection/lib/collection/item-group' ) ,
12
+ { Item } = require ( 'postman-collection/lib/collection/item' ) ,
13
+ { FormParam } = require ( 'postman-collection/lib/collection/form-param' ) ,
14
+ { RequestAuth } = require ( 'postman-collection/lib/collection/request-auth' ) ,
15
+ { Response } = require ( 'postman-collection/lib/collection/response' ) ,
16
+ { RequestBody } = require ( 'postman-collection/lib/collection/request-body' ) ,
12
17
schemaFaker = require ( '../assets/json-schema-faker.js' ) ,
13
18
deref = require ( './deref.js' ) ,
14
19
_ = require ( 'lodash' ) ,
@@ -20,6 +25,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
20
25
{ validateSchema } = require ( './ajValidation/ajvValidation' ) ,
21
26
inputValidation = require ( './30XUtils/inputValidation' ) ,
22
27
traverseUtility = require ( 'traverse' ) ,
28
+ { ParseError } = require ( './common/ParseError.js' ) ,
23
29
SCHEMA_FORMATS = {
24
30
DEFAULT : 'default' , // used for non-request-body data and json
25
31
XML : 'xml' // used for request-body XMLs
@@ -511,15 +517,15 @@ module.exports = {
511
517
if ( serverVariables ) {
512
518
_ . forOwn ( serverVariables , ( value , key ) => {
513
519
let description = this . getParameterDescription ( value ) ;
514
- variables . push ( new sdk . Variable ( {
520
+ variables . push ( new Variable ( {
515
521
key : key ,
516
522
value : value . default || '' ,
517
523
description : description
518
524
} ) ) ;
519
525
} ) ;
520
526
}
521
527
if ( keyName ) {
522
- variables . push ( new sdk . Variable ( {
528
+ variables . push ( new Variable ( {
523
529
key : keyName ,
524
530
value : serverUrl ,
525
531
type : 'string'
@@ -739,7 +745,7 @@ module.exports = {
739
745
addCollectionItemsFromWebhooks : function ( spec , generatedStore , components , options , schemaCache ) {
740
746
let webhooksObj = this . generateTrieFromPaths ( spec , options , true ) ,
741
747
webhooksTree = webhooksObj . tree ,
742
- webhooksFolder = new sdk . ItemGroup ( { name : 'Webhooks' } ) ,
748
+ webhooksFolder = new ItemGroup ( { name : 'Webhooks' } ) ,
743
749
variableStore = { } ,
744
750
webhooksVariables = [ ] ;
745
751
@@ -752,7 +758,7 @@ module.exports = {
752
758
webhooksTree . root . children . hasOwnProperty ( child ) &&
753
759
webhooksTree . root . children [ child ] . requestCount > 0
754
760
) {
755
- webhooksVariables . push ( new sdk . Variable ( {
761
+ webhooksVariables . push ( new Variable ( {
756
762
key : this . cleanWebhookName ( child ) ,
757
763
value : '/' ,
758
764
type : 'string'
@@ -838,7 +844,7 @@ module.exports = {
838
844
// variableStore contains all the kinds of variable created.
839
845
// Add only the variables with type 'collection' to generatedStore.collection.variables
840
846
if ( variableStore [ key ] . type === 'collection' ) {
841
- const collectionVar = new sdk . Variable ( variableStore [ key ] ) ;
847
+ const collectionVar = new Variable ( variableStore [ key ] ) ;
842
848
generatedStore . collection . variables . add ( collectionVar ) ;
843
849
}
844
850
}
@@ -961,7 +967,7 @@ module.exports = {
961
967
// Add all folders created from tags and corresponding operations
962
968
// Iterate from bottom to top order to maintain tag order in spec
963
969
_ . forEachRight ( tagFolders , ( tagFolder , tagName ) => {
964
- var itemGroup = new sdk . ItemGroup ( {
970
+ var itemGroup = new ItemGroup ( {
965
971
name : tagName ,
966
972
description : tagFolder . description
967
973
} ) ;
@@ -981,7 +987,7 @@ module.exports = {
981
987
// Add only the variables with type 'collection' to generatedStore.collection.variables
982
988
_ . forEach ( variableStore , ( variable ) => {
983
989
if ( variable . type === 'collection' ) {
984
- const collectionVar = new sdk . Variable ( variable ) ;
990
+ const collectionVar = new Variable ( variable ) ;
985
991
generatedStore . collection . variables . add ( collectionVar ) ;
986
992
}
987
993
} ) ;
@@ -997,7 +1003,7 @@ module.exports = {
997
1003
* resolve references while generating params.
998
1004
* @param {object } options - a standard list of options that's globally passed around. Check options.js for more.
999
1005
* @param {object } schemaCache - object storing schemaFaker and schmeResolution caches
1000
- * @returns {Array<object> } returns an array of sdk. Variable
1006
+ * @returns {Array<object> } returns an array of Collection SDK Variable
1001
1007
*/
1002
1008
convertPathVariables : function ( type , providedPathVars , commonPathVars , components , options , schemaCache ) {
1003
1009
var variables = [ ] ;
@@ -1067,7 +1073,7 @@ module.exports = {
1067
1073
if ( resource . requestCount > 1 ) {
1068
1074
// only return a Postman folder if this folder has>1 children in its subtree
1069
1075
// otherwise we can end up with 10 levels of folders with 1 request in the end
1070
- itemGroup = new sdk . ItemGroup ( {
1076
+ itemGroup = new ItemGroup ( {
1071
1077
name : resource . name
1072
1078
// TODO: have to add auth here (but first, auth to be put into the openapi tree)
1073
1079
} ) ;
@@ -1308,9 +1314,9 @@ module.exports = {
1308
1314
*/
1309
1315
generateSdkParam : function ( param , location ) {
1310
1316
const sdkElementMap = {
1311
- 'query' : sdk . QueryParam ,
1312
- 'header' : sdk . Header ,
1313
- 'path' : sdk . Variable
1317
+ 'query' : QueryParam ,
1318
+ 'header' : Header ,
1319
+ 'path' : Variable
1314
1320
} ;
1315
1321
1316
1322
let generatedParam = {
@@ -1913,7 +1919,7 @@ module.exports = {
1913
1919
convertedHeader = _ . get ( this . convertParamsWithStyle ( header , fakeData , parameterSource ,
1914
1920
components , schemaCache , options ) , '[0]' ) ;
1915
1921
1916
- reqHeader = new sdk . Header ( convertedHeader ) ;
1922
+ reqHeader = new Header ( convertedHeader ) ;
1917
1923
reqHeader . description = this . getParameterDescription ( header ) ;
1918
1924
1919
1925
return reqHeader ;
@@ -1936,7 +1942,7 @@ module.exports = {
1936
1942
originalParam ,
1937
1943
paramArray = [ ] ,
1938
1944
updateOptions = { } ,
1939
- reqBody = new sdk . RequestBody ( ) ,
1945
+ reqBody = new RequestBody ( ) ,
1940
1946
contentHeader ,
1941
1947
contentTypes = { } ,
1942
1948
rDataMode ,
@@ -2021,7 +2027,7 @@ module.exports = {
2021
2027
} ;
2022
2028
2023
2029
// add a content type header for each media type for the request body
2024
- contentHeader = new sdk . Header ( {
2030
+ contentHeader = new Header ( {
2025
2031
key : 'Content-Type' ,
2026
2032
value : URLENCODED
2027
2033
} ) ;
@@ -2088,14 +2094,14 @@ module.exports = {
2088
2094
originalParam . type === 'string' &&
2089
2095
originalParam . format === 'binary'
2090
2096
) {
2091
- param = new sdk . FormParam ( {
2097
+ param = new FormParam ( {
2092
2098
key : key ,
2093
2099
value : '' ,
2094
2100
type : 'file'
2095
2101
} ) ;
2096
2102
}
2097
2103
else {
2098
- param = new sdk . FormParam ( {
2104
+ param = new FormParam ( {
2099
2105
key : key ,
2100
2106
value : value ,
2101
2107
type : 'text'
@@ -2112,7 +2118,7 @@ module.exports = {
2112
2118
formdata : paramArray
2113
2119
} ;
2114
2120
// add a content type header for the pertaining media type
2115
- contentHeader = new sdk . Header ( {
2121
+ contentHeader = new Header ( {
2116
2122
key : 'Content-Type' ,
2117
2123
value : FORM_DATA
2118
2124
} ) ;
@@ -2177,7 +2183,7 @@ module.exports = {
2177
2183
} ;
2178
2184
}
2179
2185
2180
- contentHeader = new sdk . Header ( {
2186
+ contentHeader = new Header ( {
2181
2187
key : 'Content-Type' ,
2182
2188
value : bodyType
2183
2189
} ) ;
@@ -2246,7 +2252,7 @@ module.exports = {
2246
2252
responseMediaTypes = _ . keys ( response . content ) ;
2247
2253
2248
2254
if ( responseMediaTypes . length > 0 ) {
2249
- let acceptHeader = new sdk . Header ( {
2255
+ let acceptHeader = new Header ( {
2250
2256
key : 'Accept' ,
2251
2257
value : responseMediaTypes [ 0 ]
2252
2258
} ) ;
@@ -2256,7 +2262,7 @@ module.exports = {
2256
2262
}
2257
2263
}
2258
2264
2259
- sdkResponse = new sdk . Response ( {
2265
+ sdkResponse = new Response ( {
2260
2266
name : response . description ,
2261
2267
code : code || 500 ,
2262
2268
header : responseHeaders ,
@@ -2654,7 +2660,7 @@ module.exports = {
2654
2660
}
2655
2661
2656
2662
// creating the request object
2657
- item = new sdk . Item ( {
2663
+ item = new Item ( {
2658
2664
name : reqName ,
2659
2665
request : {
2660
2666
description : operation . description ,
@@ -2672,7 +2678,7 @@ module.exports = {
2672
2678
} ;
2673
2679
2674
2680
thisAuthObject [ authMap [ authMeta . currentHelper ] ] = authMeta . helperAttributes ;
2675
- item . request . auth = new sdk . RequestAuth ( thisAuthObject ) ;
2681
+ item . request . auth = new RequestAuth ( thisAuthObject ) ;
2676
2682
}
2677
2683
else {
2678
2684
item . request . auth = authHelper ;
0 commit comments