react-jsonschema-form
react-jsonschema-form copied to clipboard
how to pass custom AJV options
hi, I need to pass coerceTypes option to AJV initializer, any way to do this please? I realized the AJV instance is hard coded as below. seem there is no point to pass our own options.
validate.js
function createAjvInstance() {
const ajv = new Ajv({
errorDataPath: "property",
allErrors: true,
multipleOfPrecision: 8,
schemaId: "auto",
unknownFormats: "ignore",
});
// add custom formats
ajv.addFormat(
"data-url",
/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/
);
ajv.addFormat(
"color",
/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/
);
return ajv;
}
Not as of now -- you could look at #1286 though.
We do this by monkey patching the Ajv module.