Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass custom AJV options #1367

Closed
videni opened this issue Jul 26, 2019 · 2 comments
Closed

how to pass custom AJV options #1367

videni opened this issue Jul 26, 2019 · 2 comments
Labels
possibly close To confirm if this issue can be closed

Comments

@videni
Copy link

videni commented Jul 26, 2019

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;
}
@epicfaace
Copy link
Member

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

@airtonix
Copy link

We do this by monkey patching the Ajv module.

@jacqueswho jacqueswho added the possibly close To confirm if this issue can be closed label Feb 24, 2022
@stale stale bot closed this as completed Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possibly close To confirm if this issue can be closed
Projects
None yet
Development

No branches or pull requests

4 participants