Skip to content

Commit 04419ab

Browse files
committed
Update schemaUtils.js
Use of existing getRefObject
1 parent 8c657f3 commit 04419ab

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/schemaUtils.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* utils.js contains other util functions
44
*/
55

6-
const { formatDataPath, checkIsCorrectType, isKnownType,
7-
formatSchemaPathFromAJVErrorToConvertToDataPath } = require('./common/schemaUtilsCommon.js'),
6+
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
87
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
98
async = require('async'),
109
sdk = require('postman-collection'),
@@ -1370,20 +1369,19 @@ module.exports = {
13701369
* @param {*} schema bodyObject (media type) schema to use
13711370
* @param {*} example - Exampel took from the bodyObject
13721371
* @param {object} components - components defined in the OAS spec.
1372+
* @param {object} options - a standard list of options that's globally passed around. Check options.js for more.
13731373
* @returns {boolean} Wheter to use the property value of the example as the value of the
13741374
* body data
13751375
*/
1376-
useExampleValuePropAsValue(schema, example, components) {
1376+
useExampleValuePropAsValue(schema, example, components, options) {
13771377
let schemaProperties = [],
13781378
schemaObject,
1379-
schemaDataPath = '',
13801379
exampleProperties = [];
13811380
if (!schema) {
13821381
return true;
13831382
}
1384-
if (schema.$ref) {
1385-
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(schema.$ref));
1386-
schemaObject = _.get(components, schemaDataPath);
1383+
if (schema.hasOwnProperty('$ref')) {
1384+
schemaObject = this.getRefObject(schema.$ref, components, options);
13871385
}
13881386
else {
13891387
schemaObject = schema;
@@ -1445,7 +1443,7 @@ module.exports = {
14451443
bodyData = bodyObj.example;
14461444
// return example value if present else example is returned
14471445
if (bodyData.hasOwnProperty('value') &&
1448-
this.useExampleValuePropAsValue(bodyObj.schema, bodyObj.example, components)) {
1446+
this.useExampleValuePropAsValue(bodyObj.schema, bodyObj.example, components, options)) {
14491447
bodyData = bodyData.value;
14501448
}
14511449
}

0 commit comments

Comments
 (0)