How to use the validateMultiple function from tv4

Find comprehensive JavaScript tv4.validateMultiple code examples handpicked from public code repositorys.

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'];
fork icon285
star icon0
watch icon0

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
fork icon190
star icon0
watch icon34

+ 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)}`);
  }
fork icon27
star icon423
watch icon6

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);
fork icon0
star icon5
watch icon0

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) => {
fork icon0
star icon2
watch icon8

+ 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) {
fork icon25
star icon0
watch icon3

+ 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) {
fork icon22
star icon0
watch icon1

+ 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) };
fork icon0
star icon2
watch icon9

+ 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;
fork icon0
star icon0
watch icon0