before(function(){ total_schema = schemaValidatorPrivate.__get__('getPolicySchema')(); specific_date_schema = schemaValidatorPrivate.__get__('getSpecificDateSchema')(); recurring_schedule_schema = schemaValidatorPrivate.__get__('getRecurringSchema')(); schedules_schema = schemaValidatorPrivate.__get__('getScheduleSchema')(); scaling_rules_schema = schemaValidatorPrivate.__get__('getScalingRuleSchema')(); // Custom formats recreated through regular expression for testing purpose validator.addFormat('timeZoneFormat', /^[a-zA-Z0-9/]*$/i); validator.addFormat('dateFormat',/^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/i); validator.addFormat('timeFormat',/^(2[0-3]|1[0-9]|0[0-9]):([0-5][0-9])$/i); validator.addFormat('dateTimeFormat',/^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|1[0-9]|0[0-9]):([0-5][0-9])$/i); validator.addSchema(specific_date_schema, '/specific_date'); validator.addSchema(recurring_schedule_schema,'/recurring_schedule'); validator.addSchema(schedules_schema,'/schedules'); validator.addSchema(scaling_rules_schema,'/scaling_rules'); });
import JsonSchemaValidator from 'ajv' import utils from 'web3-utils' const validator = new JsonSchemaValidator({ coerceTypes: true, useDefaults: true }) validator.addFormat('address', { type: 'string', validate: utils.isAddress }) export default validator
const FileCacheService = require('cache-service-file-cache'); const fileCache = new FileCacheService({ key: 'crypto-currencies', maxRetries: 8, defaultExpiration: 200 * 60, verbose: false, }); const cache = new CacheService({ verbose: false }, [fileCache]); const superagentCache = require('superagent-cache-plugin')(cache); const superagent = require('superagent'); const Ajv = require('ajv'); const ajv = new Ajv({ allErrors: true }); ajv.addFormat('semver', value => semver.valid(value) !== null); ajv.addFormat('prepackage', () => false); ajv.addSchema(require('./schema/package.eccenca.js'), 'package.eccenca'); const nameMap = require('../nameMap'); function isEccencaPackage(p) { const search = _.chain(p) .pick(['name', 'bugs', 'repository']) .map(v => (_.isString(v) ? v : _.values(v).join('|'))) .join('|') .value(); return /(eccenca|elds)/.test(search); }
module.exports.check = function check(schema, object) { if (checkTypes.not.object(schema) || checkTypes.emptyObject(schema)) { throw new TypeError('The parameter schema must be a valid schema object'); } if (checkTypes.not.object(object) || checkTypes.emptyObject(object)) { throw new TypeError('The parameter object must be a valid object'); } const fullSchema = deref(schema); const ajvOptions = { format: 'full' }; const ajv = new Ajv(ajvOptions); const regExpr = require('./MicrorestRegExpr'); ajv.addFormat('name', regExpr.name); ajv.addFormat('version', regExpr.version); ajv.addFormat('full-date', regExpr.fullDate); ajv.addFormat('http-url', regExpr.httpUrl); ajv.addFormat('email', regExpr.email); ajv.addFormat('directory', regExpr.directory); ajv.addFormat('url-path', regExpr.urlPath); ajv.addFormat('http-method', regExpr.httpMethod); ajv.addFormat('url-parameter', regExpr.urlParameter); ajv.addFormat('type-url-parameter', regExpr.typeUrlParameter); ajv.addFormat('security-scheme', regExpr.securityScheme); const valid = ajv.validate(fullSchema, object); if (valid === false) { throw new SchemaError(ajv.errorsText()); } return valid; };