Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,