How to use ajv

Comprehensive ajv code examples:

How to use ajv.errorsText:

29
30
31
32
33
34
35
36
37
38

        let valid = validate(payload);
        if (valid && !validate.errors) {
                resolve(_.cloneDeep(payload));
        } else {
                let message = ajv.errorsText(validate.errors);
                reject(new error.InternalValidationError(message));
        }

} catch (err) {

How to use ajv.ValidationError:

86
87
88
89
90
91
92
93
94
95
        null,
        ''
    );
} catch (e) {
    myerror.message = e.message;
    throw new AJV.ValidationError([myerror]);
}

// does pointed-to data match required schema?
if (!v(tgt)) {

How to use ajv.default:

183
184
185
186
187
188
189
190
191
192
// Loading files
var json        = require(jsonPath);
var schema      = require(schemaPath);

// Config
var ajv = new Ajv.default({
    allErrors: true 
});

// Adding format support

How to use ajv.compile:

363
364
365
366
367
368
369
370
371
372
373
  const schema = datasetUtils.jsonSchema(dataset.schema.filter(p => !p['x-calculated'] && !p['x-extension']))
  schema.additionalProperties = false
  schema.properties._id = { type: 'string' }
  // super-admins can set _updatedAt and so rewrite history
  if (adminMode) schema.properties._updatedAt = { type: 'string', format: 'date-time' }
  return ajv.compile(schema)
}


async function manageAttachment (req, keepExisting) {
  if (req.is('multipart/form-data')) {