Using examples before schemas while converting response bodies

This commit is contained in:
abhijitkane
2018-11-28 19:47:04 +05:30
parent 833f0fa34c
commit 5f3b8f7716

View File

@@ -553,23 +553,23 @@ module.exports = {
// This part is to remove format:binary from any string-type properties
// will cause schemaFaker to crash if left untreated
if (bodyObj.hasOwnProperty('schema')) {
if (bodyObj.schema.hasOwnProperty('$ref')) {
bodyObj.schema = this.getRefObject(bodyObj.schema.$ref);
}
bodyData = this.options.schemaFaker ? safeSchemaFaker(bodyObj.schema || {}, this.components) : '';
}
else if (bodyObj.hasOwnProperty('examples')) {
bodyData = this.getExampleData(bodyObj.examples);
// take one of the examples as the body and not all
}
else if (bodyObj.hasOwnProperty('example')) {
if (bodyObj.hasOwnProperty('example')) {
bodyData = bodyObj.example;
// return example value if present else example is returned
if (bodyData.value) {
bodyData = bodyData.value;
}
}
else if (bodyObj.hasOwnProperty('examples')) {
bodyData = this.getExampleData(bodyObj.examples);
// take one of the examples as the body and not all
}
else if (bodyObj.hasOwnProperty('schema')) {
if (bodyObj.schema.hasOwnProperty('$ref')) {
bodyObj.schema = this.getRefObject(bodyObj.schema.$ref);
}
bodyData = this.options.schemaFaker ? safeSchemaFaker(bodyObj.schema || {}, this.components) : '';
}
return bodyData;
},