How to use the jsonschema.ValidationError function in jsonschema

To help you get started, we’ve selected a few jsonschema 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 zapier / zapier-platform-schema / lib / functional-constraints / searchOrCreateKeys.js View on Github external
errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a search (options: ${searchKeys})`,
          searchOrCreateDef,
          '/SearchOrCreateSchema',
          `instance.searchOrCreates.${key}.search`,
          'invalidKey',
          'search'
        )
      );
    }

    // Confirm searchOrCreate.create matches a creates.key
    if (!definition.creates[createKey]) {
      errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a create (options: ${createKeys})`,
          searchOrCreateDef,
          '/SearchOrCreateSchema',
          `instance.searchOrCreates.${key}.create`,
          'invalidKey',
          'create'
        )
      );
    }
  });
github zapier / zapier-platform-schema / lib / functional-constraints / searchOrCreateKeys.js View on Github external
errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a search (options: ${searchKeys})`,
          searchOrCreateDef,
          '/SearchOrCreateSchema',
          `instance.searchOrCreates.${key}.key`,
          'invalidKey',
          'key'
        )
      );
    }

    // Confirm searchOrCreate.search matches a searches.key
    if (!definition.searches[searchKey]) {
      errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a search (options: ${searchKeys})`,
          searchOrCreateDef,
          '/SearchOrCreateSchema',
          `instance.searchOrCreates.${key}.search`,
          'invalidKey',
          'search'
        )
      );
    }

    // Confirm searchOrCreate.create matches a creates.key
    if (!definition.creates[createKey]) {
      errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a create (options: ${createKeys})`,
          searchOrCreateDef,
github zapier / zapier-platform-schema / lib / functional-constraints / requiredSamples.js View on Github external
definitions = RESOURCE_METHODS.map(method => definition[method]).filter(
      Boolean
    );

    // allow method definitions to inherit the sample
    if (definition.sample) {
      definitions.forEach(methodDefinition => {
        if (methodDefinition.operation && !methodDefinition.operation.sample) {
          methodDefinition.operation.sample = definition.sample;
        }
      });
    }

    if (!definitions.length) {
      return [
        new jsonschema.ValidationError(
          'expected at least one resource operation',
          definition,
          definition.id
        )
      ];
    }
  } else {
    definitions = [definition];
  }

  return definitions.map(check).filter(Boolean);
};
github zapier / zapier-platform-schema / lib / functional-constraints / searchOrCreateKeys.js View on Github external
_.each(definition.searchOrCreates, (searchOrCreateDef, key) => {
    const searchOrCreateKey = searchOrCreateDef.key;
    const searchKey = searchOrCreateDef.search;
    const createKey = searchOrCreateDef.create;

    // Confirm searchOrCreate.key matches a searches.key (current Zapier editor limitation)
    if (!definition.searches[searchOrCreateKey]) {
      errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a search (options: ${searchKeys})`,
          searchOrCreateDef,
          '/SearchOrCreateSchema',
          `instance.searchOrCreates.${key}.key`,
          'invalidKey',
          'key'
        )
      );
    }

    // Confirm searchOrCreate.search matches a searches.key
    if (!definition.searches[searchKey]) {
      errors.push(
        new jsonschema.ValidationError(
          `must match a "key" from a search (options: ${searchKeys})`,
          searchOrCreateDef,
github zapier / zapier-platform-schema / lib / functional-constraints / matchingKeys.js View on Github external
_.each(group, (action, key) => {
      if (action.key !== key) {
        errors.push(
          new jsonschema.ValidationError(
            `must have a matching top-level key (found "${key}" and "${
              action.key
            }")`,
            action,
            `/${_.capitalize(actionType)}Schema`,
            `instance.${key}.key`,
            'invalid',
            'key'
          )
        );
      }
    });
  }
github zapier / zapier-platform-schema / lib / functional-constraints / deepNestedFields.js View on Github external
inputField,
            '/FieldSchema',
            `instance.${path}.inputFields[${index}].children`,
            'empty',
            'inputFields'
          )
        );
      } else {
        const hasDeeplyNestedChildren = _.some(
          inputField.children,
          child => child.children
        );

        if (hasDeeplyNestedChildren) {
          errors.push(
            new jsonschema.ValidationError(
              'must not contain deeply nested child fields. One level max.',
              inputField,
              '/FieldSchema',
              `instance.${path}.inputFields[${index}]`,
              'deepNesting',
              'inputFields'
            )
          );
        }
      }
    }
  });
github zapier / zapier-platform-schema / lib / functional-constraints / deepNestedFields.js View on Github external
_.each(inputFields, (inputField, index) => {
    if (inputField.children) {
      if (inputField.children.length === 0) {
        errors.push(
          new jsonschema.ValidationError(
            'must not be empty.',
            inputField,
            '/FieldSchema',
            `instance.${path}.inputFields[${index}].children`,
            'empty',
            'inputFields'
          )
        );
      } else {
        const hasDeeplyNestedChildren = _.some(
          inputField.children,
          child => child.children
        );

        if (hasDeeplyNestedChildren) {
          errors.push(
github zapier / zapier-platform-schema / lib / functional-constraints / mutuallyExclusiveFields.js View on Github external
_.each(incompatibleFields, ([firstField, secondField]) => {
      if (_.has(inputField, firstField) && _.has(inputField, secondField)) {
        errors.push(
          new jsonschema.ValidationError(
            `must not contain ${firstField} and ${secondField}, as they're mutually exclusive.`,
            inputField,
            '/FieldSchema',
            `instance.${path}.inputFields[${index}]`,
            'invalid',
            'inputFields'
          )
        );
      }
    });
  });
github zapier / zapier-platform-schema / lib / functional-constraints / requiredSamples.js View on Github external
const check = definition => {
  if (!definition.operation || _.get(definition, 'display.hidden')) {
    return null;
  }

  const samples = _.get(definition, 'operation.sample', {});
  return !_.isEmpty(samples)
    ? null
    : new jsonschema.ValidationError(
        'requires "sample", because it\'s not hidden',
        definition,
        definition.id
      );
};