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
First of all, thank you for this library, and also for the main ajv library! :) I would just like to post this in order to save other people a few hours.
I discovered yesterday that it is important to add your keywords to your ajv instance before adding this ajv-errors plugin. Otherwise, customized error messages for your custom keywords will not appear, as your validators have not run by the time this plugin goes looking for custom error messages.
Example - if you init this plugin before adding your keywords:
constajv=require('ajv')constinstance=newajv({allErrors: true,jsonPointers: true})require('ajv-errors')(instance)instance.addKeyword('testError',{validate: ()=>false})constvalidator=instance.compile({"$schema": "http://json-schema.org/draft-07/schema#","$id": "https://workflow.rlscplatform.net/PPB_ASSAY","type": "object","properties": {"test": {"type": "string","testError": true,"errorMessage": {"testError": "This is my custom error message"}}}})validator({test: "test"})console.log(validator.errors)
Hello,
First of all, thank you for this library, and also for the main
ajv
library! :) I would just like to post this in order to save other people a few hours.I discovered yesterday that it is important to add your keywords to your ajv instance before adding this
ajv-errors
plugin. Otherwise, customized error messages for your custom keywords will not appear, as your validators have not run by the time this plugin goes looking for custom error messages.Example - if you init this plugin before adding your keywords:
Outputs this:
But if you just put ajv-errors after your addKeyword:
The output becomes:
Regards,
TJ
The text was updated successfully, but these errors were encountered: