// Therefore, if the value is actually null, that's a problem (nullable is probably missing)
assert(response[prop]!==null,'"'+prop+'" was null, but schema does not specify it to be a nullable property (path: '+path+', context: '+context+')');
switch(schema[prop].type){
case'string':
assert.strictEqual(typeofresponse[prop],'string','"'+prop+'" was expected to be a string, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
break;
case'boolean':
assert.strictEqual(typeofresponse[prop],'boolean','"'+prop+'" was expected to be a boolean, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
break;
case'object':
assert.strictEqual(typeofresponse[prop],'object','"'+prop+'" was expected to be an object, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
assert.strictEqual(Array.isArray(response[prop]),true,'"'+prop+'" was expected to be an array, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
if(schema[prop].items){
// Ensure the array items have a schema defined
assert(schema[prop].items.type||schema[prop].items.allOf,'"'+prop+'" is defined to be an array, but its items have no schema defined (path: '+path+', context: '+context+')');
assert.strictEqual(typeofitem,schema[prop].items.type,'"'+prop+'" should have '+schema[prop].items.type+' items, but found '+typeofitems+' instead (path: '+path+', context: '+context+')');
});
}
}
break;
}
}
});
// Compare the response to the schema
Object.keys(response).forEach((prop)=>{
if(additionalProperties){// All bets are off
return;
it('should have examples when parameters are present',()=>{
Object.keys(context).forEach((method)=>{
constparameters=context[method].parameters;
lettestPath=path;
if(parameters){
parameters.forEach((param)=>{
assert(param.example!==null&¶m.example!==undefined,path+' has parameters without examples');
// Therefore, if the value is actually null, that's a problem (nullable is probably missing)
assert(response[prop]!==null,'"'+prop+'" was null, but schema does not specify it to be a nullable property (path: '+path+', context: '+context+')');
switch(schema[prop].type){
case'string':
assert.strictEqual(typeofresponse[prop],'string','"'+prop+'" was expected to be a string, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
break;
case'boolean':
assert.strictEqual(typeofresponse[prop],'boolean','"'+prop+'" was expected to be a boolean, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
break;
case'object':
assert.strictEqual(typeofresponse[prop],'object','"'+prop+'" was expected to be an object, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
assert.strictEqual(Array.isArray(response[prop]),true,'"'+prop+'" was expected to be an array, but was '+typeofresponse[prop]+' instead (path: '+path+', context: '+context+')');
if(schema[prop].items){
// Ensure the array items have a schema defined
assert(schema[prop].items.type||schema[prop].items.allOf,'"'+prop+'" is defined to be an array, but its items have no schema defined (path: '+path+', context: '+context+')');
assert.strictEqual(typeofitem,schema[prop].items.type,'"'+prop+'" should have '+schema[prop].items.type+' items, but found '+typeofitems+' instead (path: '+path+', context: '+context+')');
});
}
}
break;
}
}
});
// Compare the response to the schema
Object.keys(response).forEach((prop)=>{
if(additionalProperties){// All bets are off
return;
}
assert(schema[prop],'"'+prop+'" was found in response, but is not defined in schema (path: '+path+', context: '+context+')');