react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

how to pass custom AJV options

Open videni opened this issue 6 years ago • 2 comments

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;
}

videni avatar Jul 26 '19 10:07 videni

Not as of now -- you could look at #1286 though.

epicfaace avatar Jul 26 '19 16:07 epicfaace

We do this by monkey patching the Ajv module.

airtonix avatar May 27 '20 01:05 airtonix