How to use the tv4.getSchema 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 obniz / obniz / _tools / wsDocGenerator.js View on Github external
//   'display',
  //   'switch',
  //   'ble/central',
  //   'ble/peripheral',
  //   'message',
  //   'debug',
  // ];
  let md = [];

  let param = { formatter, conditions, jsonExample };
  param.defines = {};

  let moduleParams = { name: moduleName, methods: [] };
  for (let methodType of ['request', 'response']) {
    let groupUri = '/' + methodType + '/' + moduleName;
    let groupSchema = tv4.getSchema(groupUri);
    if (!groupSchema) continue;
    let commands = groupSchema.anyOf.map(elm => {
      return elm['$ref'];
    });

    let methodParams = {
      uri: groupUri,
      schema: groupSchema,
      method: methodType,
      commands: [],
    };
    for (let command of commands) {
      let schema = tv4.getSchema(command);
      let basePath = groupSchema.basePath;
      let name = command.split('/').pop();
      let commandParam = {
github sockethub / sockethub / src / validate.ts View on Github external
function processCredentials(msg, error, next) {
  msg.actor = expandProp('actor', msg.actor);
  msg.target = expandProp('target', msg.target);
  let credentialsSchema = tv4.getSchema(
    `http://sockethub.org/schemas/v0/context/${msg.context}/credentials`);
  if (! credentialsSchema) {
    return error(`no credentials schema found for ${msg.context} context`);
  }

  if (! validateCredentials(msg, credentialsSchema)) {
    return error(
      `credentials schema validation failed: ${tv4.error.dataPath} = ${tv4.error.message}`);
  }
  // passed validation, on to next handler in middleware chain
  return next(true, expandStream(msg));
}
github sockethub / sockethub / src / validate.ts View on Github external
function validateActivityStream(msg) {
  // TODO figure out a way to allow for special objects from platforms, without
  // ignoring failed activity stream schema checks
  if (! tv4.validate(msg, SockethubSchemas.ActivityStream)) {
    return tv4.getSchema(`http://sockethub.org/schemas/v0/context/${msg.context}/messages`);
  }
  return true;
}
github obniz / obniz / _tools / wsDocGenerator.js View on Github external
for (let methodType of ['request', 'response']) {
    let groupUri = '/' + methodType + '/' + moduleName;
    let groupSchema = tv4.getSchema(groupUri);
    if (!groupSchema) continue;
    let commands = groupSchema.anyOf.map(elm => {
      return elm['$ref'];
    });

    let methodParams = {
      uri: groupUri,
      schema: groupSchema,
      method: methodType,
      commands: [],
    };
    for (let command of commands) {
      let schema = tv4.getSchema(command);
      let basePath = groupSchema.basePath;
      let name = command.split('/').pop();
      let commandParam = {
        uri: command,
        schema,
        name,
        params: requestParams(schema, basePath, param.defines),
      };
      methodParams.commands.push(commandParam);
    }
    moduleParams.methods.push(methodParams);
  }
  param.module = moduleParams;

  function sortOnKeys(dict) {
    let sorted = [];
github obniz / obniz / _tools / wsDocGenerator.js View on Github external
function _checkSchema(schema, path, required, results, needDefs) {
  if (schema['$ref']) {
    schema.required = required;
    let row = {
      path: path,
      type: schema['$ref'].split('/').pop(),
      ref: schema['$ref'].split('/').pop(),
      schema: schema,
    };
    let ref = tv4.getSchema(schema['$ref']);
    if (ref) {
      needDefs[row.type] = ref;
      if (ref.example !== undefined) {
        row.example = ref.example;
      }
    }
    results.push(row);
    return;
  }

  if (
    schema.type === 'string' ||
    schema.type === 'integer' ||
    schema.type === 'boolean' ||
    schema.type === 'number' ||
    schema.type === 'null'
github Azure / azure-xplat-cli / lib / commands / arm / apiapp / lib / packaging / validations.js View on Github external
function fileIsJsonSchemaValid(schema) {
  if(_.isString(schema)) {
    schema = tv4.getSchema(schema);
  }
  return function (packageDir, filename, callback) {
    fs.exists(filename, function (exists) {
      if (!exists) { return callback(null, []); }

      fs.readFile(filename, function (err, data) {
        if (err) { return callback(err); }
        var json;
        try {
          json = JSON.parse(data.toString().trim());
        } catch (ex) {
          return callback(null, [
            fmt($('Unable to parse json file %s: line %s: %s'),
              filename, ex.lineNumber, ex.message)
          ]);
        }