How to use the jsonschema.validate 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 Ingenico-ePayments / connect-sdk-nodejs / products / deviceFingerprint.js View on Github external
var myModule = function (merchantId, paymentProductId, postData, paymentContext, cb) {
  // validate postData
  var isValidRequest = validate(postData, requestSchema);
  if (!isValidRequest.valid) {
    var logger = sdkcontext.getLogger();
    if (sdkcontext.isLoggingEnabled()) {
      logger('error', isValidRequest.errors);
    }
    throw new Error(isValidRequest.errors);
  }
  communicator.json({
    method: 'POST',
    modulePath: '/v1/' + merchantId + '/products/' + paymentProductId + '/deviceFingerprint',
    body: postData,
    paymentContext: paymentContext,
    cb: cb
  });
}
github microsoft / lsif-node / util / src / validate.ts View on Github external
if ((!LSIF.Edge.is11(edge) && !(LSIF.Edge.is1N(edge))) || edge.outV === undefined) {
			// This error was caught before
			return;
		}

		if (edge.label === undefined || !Object.values(LSIF.EdgeLabels).includes(edge.label)) {
			errors.push(new Error(edges[key].element, edge.label ? `requires property "label"` : `unknown label`));
			edges[key].invalidate();
			return;
		}

		let validation: ValidatorResult;
		switch (edge.label) {
			case LSIF.EdgeLabels.item:
				validation = validateSchema(edge, itemSchema);
				break;
			case LSIF.EdgeLabels.contains:
				validation = validateSchema(edge, e1NSchema);
				break;
			default:
				validation = validateSchema(edge, e11Schema);
		}

		const validationErrors: ValidationError[] = validation.errors.filter((error) => error.property === 'instance');
		if (validationErrors.length > 0) {
			edges[key].invalidate();
			errors.push(new Error(edges[key].element, validationErrors.join('; ')));
		}
	});
github OpenEnergyDashboard / OED / src / server / routes / compressedReadings.js View on Github external
function validateMeterBarReadingsParams(params) {
	const validParams = {
		type: 'object',
		maxProperties: 1,
		required: ['meter_ids'],
		properties: {
			meter_ids: {
				type: 'string',
				pattern: '^\\d+(?:,\\d+)*$' // Matches 1 or 1,2 or 1,2,34 (for example)
			}
		}
	};
	const paramsValidationResult = validate(params, validParams);
	return paramsValidationResult.valid;
}
github damoclark / buzzer.click / lib / message / AbstractMessage.js View on Github external
AbstractMessage.prototype.validate = function() {
    return validate(this.getJSON(), this.schema);
};
github OpenEnergyDashboard / OED / src / server / routes / groups.js View on Github external
uniqueItems: true,
				items: {
					type: 'integer'
				},
			},
			childMeters: {
				type: 'array',
				uniqueItems: true,
				items: {
					type: 'integer'
				},
			}
		}
	};

	if (!validate(req.body, validGroup).valid) {
		res.sendStatus(400);
	} else {
		try {
			const currentGroup = await Group.getByID(req.body.id);
			const currentChildGroups = await Group.getImmediateGroupsByGroupID(currentGroup.id);
			const currentChildMeters = await Group.getImmediateMetersByGroupID(currentGroup.id);

			await db.tx(t => {
				let nameChangeQuery = [];
				if (req.body.name !== currentGroup.name) {
					nameChangeQuery = currentGroup.rename(req.body.name, t);
				}

				const adoptedGroups = _.difference(req.body.childGroups, currentChildGroups);
				const adoptGroupsQueries = adoptedGroups.map(gid => currentGroup.adoptGroup(gid));
github microsoft / lsif-node / util / src / validate.ts View on Github external
return;
		}

		if (edge.label === undefined || !Object.values(LSIF.EdgeLabels).includes(edge.label)) {
			errors.push(new Error(edges[key].element, edge.label ? `requires property "label"` : `unknown label`));
			edges[key].invalidate();
			return;
		}

		let validation: ValidatorResult;
		switch (edge.label) {
			case LSIF.EdgeLabels.item:
				validation = validateSchema(edge, itemSchema);
				break;
			case LSIF.EdgeLabels.contains:
				validation = validateSchema(edge, e1NSchema);
				break;
			default:
				validation = validateSchema(edge, e11Schema);
		}

		const validationErrors: ValidationError[] = validation.errors.filter((error) => error.property === 'instance');
		if (validationErrors.length > 0) {
			edges[key].invalidate();
			errors.push(new Error(edges[key].element, validationErrors.join('; ')));
		}
	});
github apoclyps / my-dev-space / lambdas / farsetlabs / handlers / transformer.js View on Github external
const isValidEvent = event => validate(event, eventSchema).errors.length === 0;
github unmock / unmock-js / packages / unmock-core / src / generator-experimental.ts View on Github external
  ).filter(i => jsonschema.validate(part, {
    ...i,
    definitions: oas.components && oas.components.schemas
      ? Object.entries(oas.components.schemas)
        .reduce((a, b) => ({ ...a, [b[0]]: isReference(b[1]) ? changeRef(b[1]) : changeRefs(b[1])}), {})
      : {},
  } ).valid).length > 0;
github jalyna / oakdex-pokedex / src / oakdex_pokedex.js View on Github external
pokemon.map(function(p) {
    jsonValidate(p, schema, { throwError: true })
  })
};