Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { output } = response;
const inputValidationErrors = response.validations.input.map(createErrorObjectWithPrefix('request'));
const outputValidationErrors = response.validations.output.map(createErrorObjectWithPrefix('response'));
const inputOutputValidationErrors = inputValidationErrors.concat(outputValidationErrors);
if (inputOutputValidationErrors.length > 0) {
reply.header('sl-violations', JSON.stringify(inputOutputValidationErrors));
const errorViolations = outputValidationErrors.filter(
v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error]
);
if (opts.errors && errorViolations.length > 0) {
return TE.left(
ProblemJsonError.fromTemplate(
VIOLATIONS,
'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.',
{ validation: errorViolations }
)
);
}
}
inputOutputValidationErrors.forEach(validation => {
const message = `Violation: ${validation.location.join('.') || ''} ${validation.message}`;
if (validation.severity === DiagnosticSeverity[DiagnosticSeverity.Error]) {
request.log.error({ name: 'VALIDATOR' }, message);
} else if (validation.severity === DiagnosticSeverity[DiagnosticSeverity.Warning]) {
request.log.warn({ name: 'VALIDATOR' }, message);
} else {
request.log.info({ name: 'VALIDATOR' }, message);