How to use the tv4.reset 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 apiaryio / gavel.js / lib / validators / json-schema-legacy.js View on Github external
validateSchema() {
    const { jsonSchema, jsonMetaSchema } = this;

    // In case schema version is unidentified,
    // assume JSON Schema Draft V3.
    const metaSchema = jsonMetaSchema || META_SCHEMA.draftV3;

    tv4.reset();
    tv4.addSchema('', metaSchema);
    tv4.addSchema(metaSchema.$schema, metaSchema);
    const validationResult = tv4.validateResult(jsonSchema, metaSchema);

    return validationResult.valid;
  }
github apiaryio / gavel.js / lib / validators / json-schema.js View on Github external
}
    } else {
      if (metaSchemaV3.$schema) {
        tv4.reset();
        tv4.addSchema('', metaSchemaV3);
        tv4.addSchema(metaSchemaV3.$schema, metaSchemaV3);
        const validationResult = tv4.validateResult(this.schema, metaSchemaV3);

        if (validationResult && validationResult.valid) {
          this.jsonSchemaVersion = 'v3';
          return;
        }
      }

      if (metaSchemaV4.$schema) {
        tv4.reset();
        tv4.addSchema('', metaSchemaV4);
        tv4.addSchema(metaSchemaV4.$schema, metaSchemaV4);
        const validationResult = tv4.validateResult(this.schema, metaSchemaV4);

        if (validationResult && validationResult.valid) {
          this.jsonSchemaVersion = 'v4';
          return;
        }
      }

      if (this.jsonSchemaVersion === null) {
        throw new errors.JsonSchemaNotValid(
          'JSON schema is not valid draft v3 or draft v4!'
        );
      }
    }
github apiaryio / gavel.js / lib / validators / json-schema.js View on Github external
this.jsonSchemaVersion = schemaVersion;

      if (metaSchema.$schema) {
        tv4.reset();
        tv4.addSchema('', metaSchema);
        tv4.addSchema(metaSchema.$schema, metaSchema);
        const validationResult = tv4.validateResult(this.schema, metaSchema);
        if (!validationResult.valid) {
          throw new errors.JsonSchemaNotValid(
            `JSON schema is not valid draft ${this.jsonSchemaVersion}! ${validationResult.error.message} at path "${validationResult.error.dataPath}"`
          );
        }
      }
    } else {
      if (metaSchemaV3.$schema) {
        tv4.reset();
        tv4.addSchema('', metaSchemaV3);
        tv4.addSchema(metaSchemaV3.$schema, metaSchemaV3);
        const validationResult = tv4.validateResult(this.schema, metaSchemaV3);

        if (validationResult && validationResult.valid) {
          this.jsonSchemaVersion = 'v3';
          return;
        }
      }

      if (metaSchemaV4.$schema) {
        tv4.reset();
        tv4.addSchema('', metaSchemaV4);
        tv4.addSchema(metaSchemaV4.$schema, metaSchemaV4);
        const validationResult = tv4.validateResult(this.schema, metaSchemaV4);