Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'idn-email': () => true,
},
schemas: fixed,
});
if (!v(sample)) {
// FIXME: https://github.com/mafintosh/is-my-json-valid/issues/172
if (v.errors[0].field !== 'data.num') {
v.errors.forEach(e => {
fail.push(`${e.field.replace('data.', '')} ${e.message}`);
});
}
}
// z-schema
const validator = new ZSchema({
ignoreUnresolvableReferences: true,
});
Object.keys(fixed).forEach(k => {
validator.setRemoteReference(k, fixed[k]);
});
let valid;
try {
valid = validator.validate(clone(sample), clone(schema));
} catch (e) {
fail.push(`[z-schema] ${e.message}`);
}
const errors = validator.getLastErrors();
'use strict';
import process from 'process';
import path from 'path';
import ZSchema from "z-schema";
import config from './data/config';
import configSchema from './config_schema.json';
import Server from './Server';
// Validate the config up-front
let validator = new ZSchema();
validator.validate(config, configSchema);
var errors = validator.getLastErrors();
if (errors !== undefined) {
console.error("Config validation failed:");
errors.forEach(error => console.error(error));
process.exit(1);
}
let server = new Server(path.join(__dirname, 'data'));
server.listen(process.env.PORT);
process.on('SIGINT', () => server.close());
import 'ember-frost-bunsen/typedefs'
import _ from 'lodash'
import ZSchema from 'z-schema'
import {addErrorResult, aggregateResults, ensureJsonObject, validateRequiredAttribute} from './utils'
import dereference from '../dereference'
import customFormats from './custom-formats'
// Register custom formats with z-schema
_.forIn(customFormats, (validator, name) => {
ZSchema.registerFormat(name, validator)
})
const validator = new ZSchema({
noTypeless: true,
forceItems: true
})
/** currently supported model types */
const supportedTypes = ['string', 'object', 'array', 'integer', 'number', 'boolean']
/**
* Validate the children of the model object (if any exist)
* @param {String} path - the path to the field from the root of the model
* @param {BunsenModel} model - the model to validate
* @returns {BunsenValidationResult} the results of the model validation
*/
function _validateChildren (path, model) {
const results = [
{
function _getValidator(rxSchema, schemaPath = '') {
const hash = rxSchema.hash;
if (!validatorsCache[hash]) validatorsCache[hash] = {};
const validatorsOfHash = validatorsCache[hash];
if (!validatorsOfHash[schemaPath]) {
const schemaPart = schemaPath === '' ? rxSchema.jsonID : rxSchema.getSchemaByObjectPath(schemaPath);
if (!schemaPart) {
throw newRxError('VD1', {
schemaPath: schemaPath
});
}
const validator = new ZSchema();
validatorsOfHash[schemaPath] = (obj) => {
validator.validate(obj, schemaPart);
return validator;
};
}
return validatorsOfHash[schemaPath];
}
import ZSchema from 'z-schema';
const validator = new ZSchema();
const resourceSchema = {
type: 'object',
properties: {
schema: {
type: ['object', 'string'],
},
request: {
type: 'object',
properties: {
endpoint: {
type: 'string',
},
headers: {
type: 'object',
},
method: {
import 'ember-frost-bunsen/typedefs'
import _ from 'lodash'
import ZSchema from 'z-schema'
const schemaValidator = new ZSchema({
breakOnFirstError: false
})
export const integerRegex = '^[0-9]*$'
export const ipAddressRangeRegex = '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}' +
'([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/(\\d|[1-2]\\d|3[0-2]))?$'
/**
* Go through the errors and convert any 'String does not match pattern...' errors for known regex patterns
* @param {BunsenValidationError[]} errors - the list of errors which will be updated in-place
*/
export function translateRegexErrors (errors) {
const regexLabels = {
[integerRegex]: 'for an integer',
[ipAddressRangeRegex]: 'for an IP address'
}
function _getValidator(rxSchema) {
var schemaPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var hash = rxSchema.hash;
if (!validatorsCache[hash]) validatorsCache[hash] = {};
var validatorsOfHash = validatorsCache[hash];
if (!validatorsOfHash[schemaPath]) {
var schemaPart = schemaPath === '' ? rxSchema.jsonID : rxSchema.getSchemaByObjectPath(schemaPath);
if (!schemaPart) {
throw newRxError('VD1', {
schemaPath: schemaPath
});
}
var validator = new ZSchema();
validatorsOfHash[schemaPath] = function (obj) {
validator.validate(obj, schemaPart);
return validator;
};
}
return validatorsOfHash[schemaPath];
}
/**