@@ -1361,35 +1361,27 @@ module.exports = {
1361
1361
} ,
1362
1362
1363
1363
/**
1364
- * Identifies if the example.value should be used as value of the body
1365
- * This is needed because there are cases that the example object has a property
1366
- * called value like: example = { id: 1, value: "someValue" }
1367
- * In this case the body value should be the whole example object and not the property called value
1368
- * The property value belongs to the example object not the example OAS spec property
1364
+ * Identifies if the given schema has the property "value"
1369
1365
* @param {* } schema bodyObject (media type) schema to use
1370
- * @param {* } example - Exampel took from the bodyObject
1371
1366
* @param {object } components - components defined in the OAS spec.
1372
1367
* @param {object } options - a standard list of options that's globally passed around. Check options.js for more.
1373
1368
* @returns {boolean } Wheter to use the property value of the example as the value of the
1374
1369
* body data
1375
1370
*/
1376
- useExampleValuePropAsValue ( schema , example , components , options ) {
1377
- let schemaProperties = [ ] ,
1378
- schemaObject ,
1379
- exampleProperties = [ ] ;
1371
+ schemaHasValueProp ( schema , components , options ) {
1372
+ let schemaHasValue = false ,
1373
+ schemaObject ;
1380
1374
if ( ! schema ) {
1381
- return true ;
1375
+ return false ;
1382
1376
}
1383
- if ( schema . hasOwnProperty ( ' $ref' ) ) {
1377
+ if ( schema . $ref ) {
1384
1378
schemaObject = this . getRefObject ( schema . $ref , components , options ) ;
1385
1379
}
1386
1380
else {
1387
1381
schemaObject = schema ;
1388
1382
}
1389
-
1390
- schemaProperties = Object . keys ( schemaObject . properties ) . sort ( ) ;
1391
- exampleProperties = Object . keys ( example . value ) . sort ( ) ;
1392
- return JSON . stringify ( schemaProperties ) === JSON . stringify ( exampleProperties ) ;
1383
+ schemaHasValue = schemaObject . properties . hasOwnProperty ( 'value' ) ;
1384
+ return schemaHasValue ;
1393
1385
} ,
1394
1386
1395
1387
/**
@@ -1443,7 +1435,7 @@ module.exports = {
1443
1435
bodyData = bodyObj . example ;
1444
1436
// return example value if present else example is returned
1445
1437
if ( bodyData . hasOwnProperty ( 'value' ) &&
1446
- this . useExampleValuePropAsValue ( bodyObj . schema , bodyObj . example , components , options ) ) {
1438
+ ! this . schemaHasValueProp ( bodyObj . schema , components , options ) ) {
1447
1439
bodyData = bodyData . value ;
1448
1440
}
1449
1441
}
0 commit comments