Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
} 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!'
);
}
}
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);