loadScheme(path.join(__dirname, "/state_sync_scheme.json"), (err, preScheme) => { if (err) { callback(err); } else { const scheme = preScheme[MsgTypes.SYNC_BCODE_REQ]; const v = new Validator(); const isValid = v.validate(testObj, scheme).valid; callback(null, isValid); } });
validate() { var v = new JSONValidator(); return v.validate(this, schema); }
validateJson(answer) { const Validator = require('jsonschema').Validator const v = new Validator() const resultSchema = { "type": "object", "properties": { "result": {"type": "number"}, }, "required": ["result"] } v.validate(answer, resultSchema, {throwError: true}) }
function validateShippingAddress(shippingAddress) { return validator.validate(shippingAddress, shippingAddressSchema.id); }
router.get('/', async(req, res, next) => { var v = new Validator(); v.addSchema(UserAddressSchema, '/SimpleAddress'); console.log(UserSchema) validated = v.validate(req.body, UserSchema); if(validated.errors.length != 0) { res.status(200).send( { status: 200, message: validated.errors.map(error => ({ property: error.property, message: error.message })) } ); } res.status(200).send({ status: 200, message: validated }); })
router.put('/:namespace/:id/env/:env', bodyParser.json({ strict: false, limit: bodyParserLimit }), async (req, res) => { const validationResult = new Validator().validate(req.body, schemas['functions/env']); const memoryStorage = req.app.get('memoryStorage'); if (!validationResult.valid) { const error = 'Invalid instance'; const details = validationResult.errors.map(e => e.toString()); res.status(400).json({ error, details }); return; } const { namespace, id, env, } = req.params; try { await memoryStorage .putCodeEnviromentVariable(namespace, id, env, req.body); res.status(204).end(); } catch (err) { log.error(`[${namespace}:${id}] Failed to set enviroment variable ${env}, error: ${err}`); res.status(err.statusCode || 500).json({ error: err.message }); } });
const validate = (json) => { const v = new Validator(); const list = fileReader.readAsJson(json); const errors = []; for (const l in list) { const error = v.validate(list[l], schema) .errors.map(e => `Item: ${e.instance} - ${e.stack}`); if (Object.keys(list[l]).length !== 8) { errors.push(`Item: ${l} - Don't have the correct number of attributes.`); } errors.push(error); } const errorsFlattened = errors.reduce((a, b) => a.concat(b), []); if (errorsFlattened.length > 0) { console.log('The unified list you provided has errors:'); errorsFlattened.forEach(e => { console.error(e); }); } }
loadScheme(path.join(__dirname, "/state_sync_scheme.json"), (err, preScheme) => { if (err) { return callback(err); } else { const scheme = preScheme[MsgTypes.SYNC_STATE_REQ]; const v = new Validator(); let isValid = true; if (Array.isArray(testObj)) { for (let i = 0; i < testObj.length; ++i) { if (!v.validate(testObj[i], scheme).valid) { isValid = false; break; } } } else { isValid = v.validate(testObj, scheme).valid; } return callback(null, isValid); } });
const validateJsonSchema = obj => validator.validate(obj, jsonSchema)
loadScheme(path.join(__dirname, "/state_sync_scheme.json"), (err, preScheme) => { if (err) { callback(err); } else { const scheme = preScheme[MsgTypes.SYNC_STATE_RES]; const v = new Validator(); const isValid = v.validate(testObj, scheme).valid; callback(null, isValid); } });
loadScheme(path.join(__dirname, "/state_sync_scheme.json"), (err, preScheme) => { if (err) { callback(err); } else { const scheme = preScheme[MsgTypes.SYNC_BCODE_RES]; const v = new Validator(); const isValid = v.validate(testObj, scheme).valid; callback(null, isValid); } });
validate() { var v = new JSONValidator(); return v.validate(this, schema); }
validate() { var v = new JSONValidator(); return v.validate(this, schema); }
function validateQuoteRequest(quoteRequest) { return validator.validate(quoteRequest, quoteRequestSchema.id); }
function validateShipmentRequest(shipmentRequest) { return validator.validate(shipmentRequest, shipmentRequestSchema.id); }