How to use the validateMultiple function from tv4
Find comprehensive JavaScript tv4.validateMultiple code examples handpicked from public code repositorys.
GitHub: planger/jsonforms
96 97 98 99 100 101 102 103 104 105
this.convertAllDates(instance); this.checkObjects = []; this.clear(instance); // TODO let results = tv4.validateMultiple(instance, schema); results['errors'].forEach((error) => { if (error['schemaPath'].indexOf('required') !== -1) { let propName = error['dataPath'] + '/' + error['params']['key'];
285
0
0
GitHub: geraintluff/tv4
54 55 56 57 58 59 60 61 62 63
## Usage 3: Multiple errors Normally, `tv4` stops when it encounters the first validation error. However, you can collect an array of validation errors using: ```javascript var result = tv4.validateMultiple(data, schema); ``` The result will look something like: ```json
190
0
34
+ 3 other calls in file
47 48 49 50 51 52 53 54 55 56
* @see ./installLogsPrinter.d.ts */ function installLogsPrinter(on, options = {}) { options.printLogsToFile = options.printLogsToFile || "onFail"; options.printLogsToConsole = options.printLogsToConsole || "onFail"; const result = tv4.validateMultiple(options, schema); if (!result.valid) { throw new CtrError(`Invalid plugin install options: ${tv4ErrorTransformer.toReadableString(result.errors)}`); }
27
423
6
48 49 50 51 52 53 54 55 56
var out = require('miniwrite').console(); var style = require('ministyle').ansi(); var reporter = require('tv4-reporter').getReporter(out, style); // now validate var result = tv4.validateMultiple(myValue, mySchema); if (!result.valid || result.missing.length > 0) { // get data object (might get these in bulk/async from somewhere) var res = reporter.createTest(mySchema, myValue, 'my special test', true);
0
5
0
188 189 190 191 192 193 194 195 196 197
* @param {function} [callback] called with (error, result) */ function tv4Validate(data, schema, callback) { return Promise.resolve() .then(() => { const result = tv4.validateMultiple(data, schema); if (result.missing.length > 0) { // Missing Schemas return Promise.all( result.missing.map((schemaID) => {
0
2
8
+ 5 other calls in file
12 13 14 15 16 17 18 19 20 21
//Since data will be coming in from a query parameter, it comes in as a string //rather than a JSON object. So we do our best to cast it to the desired type. value = castValueFromString(schema, value); var result = tv4.validateMultiple(value, schema); return result; }; exports.validateJSONType = function (schema, value) {
25
0
3
+ 7 other calls in file
8 9 10 11 12 13 14 15 16 17
const schemaJson = require('../../schemas/Condition.json') tv4.addFormat(formats) class Condition { static validate (condition) { return tv4.validateMultiple(condition, schemaJson) } static testFulfillment (condition, fulfillment) { switch (condition.type) {
22
0
1
+ 3 other calls in file
13 14 15 16 17 18 19 20 21 22
return (e.dataPath) ? e.dataPath + " -- " + e.message : e.message; } exports.validateJsonSyntax = function (json, schemaUri) { var schema = tv4.getSchema(schemaUri); var ret = tv4.validateMultiple(json, schema, true); return { valid: ret.valid, errors: _.map(ret.errors, validationErrorToString), missing: _.map(ret.missing, validationErrorToString) };
0
2
9
+ 3 other calls in file
17 18 19 20 21 22 23 24 25 26
switch (mySchema.validate) { case 'params': data = req.params; break; } res = tv4.validateMultiple(data, mySchema.schema); } } return res;
0
0
0
tv4.validate is the most popular function in tv4 (982 examples)