All files / src/plugins/validation/2and3/structural-validation validator.js

90.91% Statements 10/11
40% Branches 2/5
66.67% Functions 2/3
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2828x 28x   28x 28x   28x 28x   28x 89x 89x                                
const JSONSchema = require('jsonschema');
const { transformPathToArray } = require('../../../../path-translator.js');
 
const jsonSchema = require('./jsonSchema');
const { getLineNumberForPath } = require('../../../ast/ast');
 
const validator = new JSONSchema.Validator();
validator.addSchema(jsonSchema);
 
module.exports.validate = function({ jsSpec, specStr, settings = {} }) {
  settings.schemas.forEach(schema => validator.addSchema(schema));
  return validator
    .validate(jsSpec, settings.testSchema || {})
    .errors.map(err => {
      return {
        level: 'error',
        line: getLineNumberForPath(
          specStr,
          transformPathToArray(err.property, jsSpec) || []
        ),
        path: err.property.replace('instance.', ''),
        message: err.message,
        source: 'schema',
        original: err // this won't make it into state, but is still helpful
      };
    });
};