@@ -16,7 +16,6 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
16
16
openApiErr = require ( './error.js' ) ,
17
17
ajvValidationError = require ( './ajValidation/ajvValidationError' ) ,
18
18
utils = require ( './utils.js' ) ,
19
- defaultOptions = require ( '../lib/options.js' ) . getOptions ( 'use' ) ,
20
19
{ Node, Trie } = require ( './trie.js' ) ,
21
20
{ validateSchema } = require ( './ajValidation/ajvValidation' ) ,
22
21
inputValidation = require ( './30XUtils/inputValidation' ) ,
@@ -523,7 +522,6 @@ module.exports = {
523
522
* @returns {* } combined requestParams from operation and path params.
524
523
*/
525
524
getRequestParams : function ( operationParam , pathParam , components , options ) {
526
- options = _ . merge ( { } , defaultOptions , options ) ;
527
525
if ( ! Array . isArray ( operationParam ) ) {
528
526
operationParam = [ ] ;
529
527
}
@@ -579,7 +577,6 @@ module.exports = {
579
577
* @returns {Object } - The final object consists of the tree structure
580
578
*/
581
579
generateTrieFromPaths : function ( spec , options , fromWebhooks = false ) {
582
- options = _ . merge ( { } , defaultOptions , options ) ;
583
580
let concreteUtils = getConcreteSchemaUtils ( { type : 'json' , data : spec } ) ,
584
581
specComponentsAndUtils = {
585
582
concreteUtils
@@ -981,8 +978,6 @@ module.exports = {
981
978
* @returns {Array<object> } returns an array of sdk.Variable
982
979
*/
983
980
convertPathVariables : function ( type , providedPathVars , commonPathVars , components , options , schemaCache ) {
984
- options = _ . merge ( { } , defaultOptions , options ) ;
985
-
986
981
var variables = [ ] ;
987
982
// converting the base uri path variables, if any
988
983
// commonPathVars is an object for type = root/method
@@ -1036,7 +1031,6 @@ module.exports = {
1036
1031
*/
1037
1032
convertChildToItemGroup : function ( openapi , child , components , options ,
1038
1033
schemaCache , variableStore , fromWebhooks = false ) {
1039
- options = _ . merge ( { } , defaultOptions , options ) ;
1040
1034
1041
1035
var resource = child ,
1042
1036
itemGroup ,
@@ -1398,8 +1392,6 @@ module.exports = {
1398
1392
* @return {object } responseBody, contentType header needed
1399
1393
*/
1400
1394
convertToPmResponseBody : function ( contentObj , components , options , schemaCache ) {
1401
- options = _ . merge ( { } , defaultOptions , options ) ;
1402
-
1403
1395
var responseBody , cTypeHeader , hasComputedType , cTypes ,
1404
1396
isJsonLike = false ;
1405
1397
if ( ! contentObj ) {
@@ -1512,8 +1504,6 @@ module.exports = {
1512
1504
* @returns {* } first example in the input map type
1513
1505
*/
1514
1506
getExampleData : function ( exampleObj , components , options ) {
1515
- options = _ . merge ( { } , defaultOptions , options ) ;
1516
-
1517
1507
var example ,
1518
1508
exampleKey ;
1519
1509
@@ -1556,7 +1546,6 @@ module.exports = {
1556
1546
convertToPmBodyData : function ( bodyObj , requestType , contentType , parameterSourceOption ,
1557
1547
indentCharacter , components , options , schemaCache ) {
1558
1548
1559
- options = _ . merge ( { } , defaultOptions , options ) ;
1560
1549
var bodyData = '' ,
1561
1550
schemaFormat = SCHEMA_FORMATS . DEFAULT ,
1562
1551
schemaType ,
@@ -1672,7 +1661,6 @@ module.exports = {
1672
1661
* @returns {array } converted queryparam
1673
1662
*/
1674
1663
convertToPmQueryParameters : function ( param , requestType , components , options , schemaCache ) {
1675
- options = _ . merge ( { } , defaultOptions , options ) ;
1676
1664
var pmParams = [ ] ,
1677
1665
paramValue ,
1678
1666
resolveTo = this . resolveToExampleOrSchema ( requestType , options . requestParametersResolution ,
@@ -1848,8 +1836,6 @@ module.exports = {
1848
1836
* @returns {Object } instance of a Postman SDK Header
1849
1837
*/
1850
1838
convertToPmHeader : function ( header , requestType , parameterSource , components , options , schemaCache ) {
1851
- options = _ . merge ( { } , defaultOptions , options ) ;
1852
-
1853
1839
var fakeData ,
1854
1840
convertedHeader ,
1855
1841
reqHeader ,
@@ -1891,7 +1877,6 @@ module.exports = {
1891
1877
* @returns {Object } - Postman requestBody and Content-Type Header
1892
1878
*/
1893
1879
convertToPmBody : function ( requestBody , requestType , components , options , schemaCache ) {
1894
- options = _ . merge ( { } , defaultOptions , options ) ;
1895
1880
var contentObj , // content is required
1896
1881
bodyData ,
1897
1882
param ,
@@ -2175,7 +2160,6 @@ module.exports = {
2175
2160
* @returns {Object } postman response
2176
2161
*/
2177
2162
convertToPmResponse : function ( response , code , originalRequest , components , options , schemaCache ) {
2178
- options = _ . merge ( { } , defaultOptions , options ) ;
2179
2163
var responseHeaders = [ ] ,
2180
2164
previewLanguage = 'text' ,
2181
2165
responseBodyWrapper ,
@@ -2287,17 +2271,21 @@ module.exports = {
2287
2271
* @param {object } components - components defined in the OAS spec. These are used to
2288
2272
* resolve references while generating params.
2289
2273
* @param {object } options - a standard list of options that's globally passed around. Check options.js for more.
2274
+ * @param {* } seenRef - References that are repeated. Used to identify circular references.
2290
2275
* @returns {Object } reference object from the saved components
2291
2276
* @no -unit-tests
2292
2277
*/
2293
- getRefObject : function ( $ref , components , options ) {
2294
- options = _ . merge ( { } , defaultOptions , options ) ;
2278
+ getRefObject : function ( $ref , components , options , seenRef = { } ) {
2295
2279
var refObj , savedSchema ;
2296
2280
2297
2281
if ( typeof $ref !== 'string' ) {
2298
2282
return { value : `Invalid $ref: ${ $ref } was found` } ;
2299
2283
}
2300
2284
2285
+ if ( seenRef [ $ref ] ) {
2286
+ return { value : `Error: "${ $ref } " contains circular references in it.` } ;
2287
+ }
2288
+
2301
2289
savedSchema = $ref . split ( '/' ) . slice ( 1 ) . map ( ( elem ) => {
2302
2290
// https://swagger.io/docs/specification/using-ref#escape
2303
2291
// since / is the default delimiter, slashes are escaped with ~1
@@ -2328,10 +2316,16 @@ module.exports = {
2328
2316
return { value : `reference ${ $ref } not found in the given specification` } ;
2329
2317
}
2330
2318
2319
+ // Mark current $ref as seen while processing it further
2320
+ seenRef [ $ref ] = true ;
2321
+
2331
2322
if ( refObj . $ref ) {
2332
- return this . getRefObject ( refObj . $ref , components , options ) ;
2323
+ return this . getRefObject ( refObj . $ref , components , options , seenRef ) ;
2333
2324
}
2334
2325
2326
+ // Unmark current $ref once resolved
2327
+ seenRef [ $ref ] = false ;
2328
+
2335
2329
return refObj ;
2336
2330
} ,
2337
2331
@@ -2461,7 +2455,6 @@ module.exports = {
2461
2455
*/
2462
2456
convertRequestToItem : function ( openapi , operationItem , components ,
2463
2457
options , schemaCache , variableStore , fromWebhooks = false ) {
2464
- options = _ . merge ( { } , defaultOptions , options ) ;
2465
2458
var reqName ,
2466
2459
pathVariables = openapi . baseUrlVariables ,
2467
2460
operation = operationItem . properties ,
@@ -2825,7 +2818,6 @@ module.exports = {
2825
2818
* @returns {* } array of all query params
2826
2819
*/
2827
2820
convertToPmQueryArray : function ( reqParams , requestType , components , options , schemaCache ) {
2828
- options = _ . merge ( { } , defaultOptions , options ) ;
2829
2821
let requestQueryParams = [ ] ;
2830
2822
_ . forEach ( reqParams . query , ( queryParam ) => {
2831
2823
this . convertToPmQueryParameters ( queryParam , requestType , components , options , schemaCache ) . forEach ( ( pmParam ) => {
0 commit comments