You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class for data validation
`export class SchemaValidator {
static ajv = new Ajv({ allErrors: true, verbose: true });
public static validate<T>(schema: SchemaFile, data: T): boolean {
const schemaContent = JSON.parse(fs.readFileSync(path.join(__dirname, 'path', schema), 'utf-8'));
if (!this.ajv.validateSchema(schemaContent)) {
console.error(`Schema is not valid.`);
}
const isValid = this.ajv.validate(schemaContent, data);
if (!isValid) {
const errorMessages = this.ajv.errorsText();
logger.error(`Validation failed : ${errorMessages}`);
return false;
}
return true;
}
}`
I use JSON schema described in a separate file.
How to get the full output when validation fails so that I can understand which part exactly does not match?
For example, values in the enum did not match, or input data had some additional properties, missing properties, etc.
Right now I see only data.payload.something should be equal to one of the allowed values
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there.
I have a class for data validation
`export class SchemaValidator {
static ajv = new Ajv({ allErrors: true, verbose: true });
}`
I use JSON schema described in a separate file.
How to get the full output when validation fails so that I can understand which part exactly does not match?
For example, values in the enum did not match, or input data had some additional properties, missing properties, etc.
Right now I see only
data.payload.something should be equal to one of the allowed values
Beta Was this translation helpful? Give feedback.
All reactions