How to use the jsonschema/lib/helpers.FORMAT_REGEXPS.email function in jsonschema

To help you get started, we’ve selected a few jsonschema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudwan / gohan_webui / src / Form / formComponents / validator / index.js View on Github external
import {Validator} from 'jsonschema';
import {FORMAT_REGEXPS} from 'jsonschema/lib/helpers';
import Ajv from 'ajv';
import metaSchema from 'ajv/lib/refs/json-schema-draft-04.json';

import cidrFormat from './cidrFormat';
import macFormat from './macFormat';
import ipV6Format from './ipV6Format';
import ipV4Format from './ipV4Format';
import uuidFormat from './uuidFormat';
import emailFormat from './emailFormat';
import versionConstraintFormat from './versionConstraintFormat';

// Override jsonschema built in regex.
FORMAT_REGEXPS.email = emailFormat;
FORMAT_REGEXPS.ipv4 = ipV4Format;
FORMAT_REGEXPS.ipv6 = ipV6Format;

// Custom jsonschema validators.
Validator.prototype.customFormats.mac = macFormat;
Validator.prototype.customFormats.cidr = cidrFormat;
Validator.prototype.customFormats.uuid = uuidFormat;
Validator.prototype.customFormats['version-constraint'] = versionConstraintFormat;

const ajv = new Ajv({
  meta: false,
  extendRefs: true,
  unknownFormats: 'ignore',
  allErrors: true,
  formats: {
    cidr: cidrFormat,