Add test and code improvements

Add test and code improvements
This commit is contained in:
Luis Tejeda
2022-04-13 12:03:50 -05:00
committed by Erik Mendoza
parent ac9df06e84
commit d226580b52
3 changed files with 74 additions and 6 deletions

View File

@@ -1361,14 +1361,25 @@ module.exports = {
return example;
},
useExampleValueAsValue(schema, example, components) {
let isCandidate = true,
schemaProperties = [],
/**
* Identifies if the example.value should be used as value of the body
* This is needed because there are cases that the example object has a property
* called value like: example = { id: 1, value: "someValue" }
* In this case the body value should be the whole example object and not the property called value
* The property value belongs to the example object not the example OAS spec property
* @param {*} schema bodyObject (media type) schema to use
* @param {*} example - Exampel took from the bodyObject
* @param {object} components - components defined in the OAS spec.
* @returns {boolean} Wheter to use the property value of the example as the value of the
* body data
*/
useExampleValuePropAsValue(schema, example, components) {
let schemaProperties = [],
schemaObject,
schemaDataPath = '',
exampleProperties = [];
if (!schema) {
return isCandidate;
return false;
}
if (schema.$ref) {
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(schema.$ref));
@@ -1434,7 +1445,7 @@ module.exports = {
bodyData = bodyObj.example;
// return example value if present else example is returned
if (bodyData.hasOwnProperty('value') &&
this.useExampleValueAsValue(bodyObj.schema, bodyObj.example, components)) {
this.useExampleValuePropAsValue(bodyObj.schema, bodyObj.example, components)) {
bodyData = bodyData.value;
}
}