How to use the tv4.error function in tv4

To help you get started, we’ve selected a few tv4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mhhf / spore / src / lib / publish.es6 View on Github external
var validateJson = function( working_dir, json ) {
    
    var valide = tv4.validate( json, require('../specs/user_'+config.client_version+'.json') );
    if( !valide ) {
      console.log('ERROR'.red +': spore.json is not valide:\n' + tv4.error.message );
      process.exit();
    }
    
    let files = json.files;
    
    // Check if any files are about to be included
    if( files.length == 0 ) 
      throw new Error('Include some files first');
    
    // Check if linked files exists
    files.forEach( ( file ) => {
      let exists = fs.existsSync( working_dir + '/' + file );
      if( !exists ) throw new Error(`File ${file} can't be found in ${working_dir}`);
    });
  }
github kr1sp1n / node-vault / src / index.js View on Github external
function validate(json, schema) {
    // ignore validation if no schema
    if (schema === undefined) return Promise.resolve();
    const valid = tv4.validate(json, schema);
    if (!valid) {
      debug(tv4.error.dataPath);
      debug(tv4.error.message);
      return Promise.reject(tv4.error);
    }
    return Promise.resolve();
  }
github parse-community / parse-server / src / LiveQuery / ParseLiveQueryServer.js View on Github external
if (typeof request === 'string') {
        try {
          request = JSON.parse(request);
        } catch (e) {
          logger.error('unable to parse request', request, e);
          return;
        }
      }
      logger.verbose('Request: %j', request);

      // Check whether this request is a valid request, return error directly if not
      if (
        !tv4.validate(request, RequestSchema['general']) ||
        !tv4.validate(request, RequestSchema[request.op])
      ) {
        Client.pushError(parseWebsocket, 1, tv4.error.message);
        logger.error('Connect message error %s', tv4.error.message);
        return;
      }

      switch (request.op) {
        case 'connect':
          this._handleConnect(parseWebsocket, request);
          break;
        case 'subscribe':
          this._handleSubscribe(parseWebsocket, request);
          break;
        case 'update':
          this._handleUpdateSubscription(parseWebsocket, request);
          break;
        case 'unsubscribe':
          this._handleUnsubscribe(parseWebsocket, request);
github kr1sp1n / node-vault / src / index.js View on Github external
function validate(json, schema) {
    // ignore validation if no schema
    if (schema === undefined) return Promise.resolve();
    const valid = tv4.validate(json, schema);
    if (!valid) {
      debug(tv4.error.dataPath);
      debug(tv4.error.message);
      return Promise.reject(tv4.error);
    }
    return Promise.resolve();
  }
github parse-community / parse-server / src / LiveQuery / ParseLiveQueryServer.js View on Github external
try {
          request = JSON.parse(request);
        } catch (e) {
          logger.error('unable to parse request', request, e);
          return;
        }
      }
      logger.verbose('Request: %j', request);

      // Check whether this request is a valid request, return error directly if not
      if (
        !tv4.validate(request, RequestSchema['general']) ||
        !tv4.validate(request, RequestSchema[request.op])
      ) {
        Client.pushError(parseWebsocket, 1, tv4.error.message);
        logger.error('Connect message error %s', tv4.error.message);
        return;
      }

      switch (request.op) {
        case 'connect':
          this._handleConnect(parseWebsocket, request);
          break;
        case 'subscribe':
          this._handleSubscribe(parseWebsocket, request);
          break;
        case 'update':
          this._handleUpdateSubscription(parseWebsocket, request);
          break;
        case 'unsubscribe':
          this._handleUnsubscribe(parseWebsocket, request);
          break;
github dapphub / dapple / test / dapplerc.js View on Github external
it('loads configuration files into its data property', function () {
    var expected = fs.readYamlSync(fixtureRCExpanded);
    var rc = DappleRC.create({paths: [fixtureRC]});
    assert.deepEqual(rc.data, expected);
    var valid = tv4.validate(rc.data, dapplercSchema);
    assert(valid, 'dapplerc is not valid by schema' + tv4.error);
  });
github apiaryio / gavel.js / test / cucumber / step_definitions / validators_steps.js View on Github external
function(model, schema, callback) {
      const valid = tv4.validate(
        this.results.fields[this.component],
        JSON.parse(schema)
      );
      if (!valid) {
        return callback(
          new Error(
            'Expected no validation errors on schema but got:\n' +
              JSON.stringify(tv4.error, null, 2)
          )
        );
      } else {
        return callback();
      }
    }
  );
github APIDevTools / swagger-express-middleware / lib / helpers / json-schema.js View on Github external
function jsonValidate (schema, value, propPath) {
  if (tv4.validate(value, schema)) {
    return true;
  }
  else if (propPath !== undefined) {
    let dataPath = propPath ? propPath + "." + tv4.error.dataPath : tv4.error.dataPath;
    throw ono(tv4.error, { status: 400 }, 'JSON Schema validation error. \nData path: "%s" \nSchema path: "%s"',
      dataPath, tv4.error.schemaPath);
  }
  else {
    throw ono(tv4.error, { status: 400 }, "JSON Schema validation error.");
  }
}
github JamesMessinger / swagger-server / lib / validation / validate-schema.js View on Github external
function jsonValidate(value, schema, detailedErrorMessage) {
    if (tv4.validate(value, schema)) {
      return true;
    }
    else if (detailedErrorMessage) {
      throw syntaxError('%s \nData path: "%s" \nSchema path: "%s"\n',
        tv4.error.message, tv4.error.dataPath, tv4.error.schemaPath);
    }
    else {
      throw syntaxError(tv4.error.message);
    }
  }
github Azure / azure-resource-manager-schemas / tools / Tests / tv4Tests.js View on Github external
test.run(function () {
    var result = tv4.validate(schema, metaSchema);
    assert.False(result);
    assert.NotNull(tv4.error);
    for (var propertyName in expectedErrorValues) {
      assert.Equal(expectedErrorValues[propertyName], tv4.error[propertyName]);
    }
  });
}