Skip to content

Commit 9410b6d

Browse files
committed
Search for value prop in schema
Search for value prop in schema
1 parent 04419ab commit 9410b6d

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

lib/schemaUtils.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,35 +1361,27 @@ module.exports = {
13611361
},
13621362

13631363
/**
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"
13691365
* @param {*} schema bodyObject (media type) schema to use
1370-
* @param {*} example - Exampel took from the bodyObject
13711366
* @param {object} components - components defined in the OAS spec.
13721367
* @param {object} options - a standard list of options that's globally passed around. Check options.js for more.
13731368
* @returns {boolean} Wheter to use the property value of the example as the value of the
13741369
* body data
13751370
*/
1376-
useExampleValuePropAsValue(schema, example, components, options) {
1377-
let schemaProperties = [],
1378-
schemaObject,
1379-
exampleProperties = [];
1371+
schemaHasValueProp(schema, components, options) {
1372+
let schemaHasValue = false,
1373+
schemaObject;
13801374
if (!schema) {
1381-
return true;
1375+
return false;
13821376
}
1383-
if (schema.hasOwnProperty('$ref')) {
1377+
if (schema.$ref) {
13841378
schemaObject = this.getRefObject(schema.$ref, components, options);
13851379
}
13861380
else {
13871381
schemaObject = schema;
13881382
}
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;
13931385
},
13941386

13951387
/**
@@ -1443,7 +1435,7 @@ module.exports = {
14431435
bodyData = bodyObj.example;
14441436
// return example value if present else example is returned
14451437
if (bodyData.hasOwnProperty('value') &&
1446-
this.useExampleValuePropAsValue(bodyObj.schema, bodyObj.example, components, options)) {
1438+
!this.schemaHasValueProp(bodyObj.schema, components, options)) {
14471439
bodyData = bodyData.value;
14481440
}
14491441
}

test/unit/base.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
11111111
});
11121112
});
11131113

1114-
it('[Github #10752]: Should convert value property in example' +
1114+
it('Should convert value property in example' +
11151115
valuePropInExample, function(done) {
11161116
var openapi = fs.readFileSync(valuePropInExample, 'utf8');
11171117
Converter.convert({ type: 'string', data: openapi },

0 commit comments

Comments
 (0)