@cfworker/json-schema
Version:
A JSON schema validator that will run on Cloudflare workers. Supports drafts 4, 7, 2019-09, and 2020-12.
24 lines (23 loc) • 657 B
JavaScript
import { dereference } from './dereference.js';
import { validate } from './validate.js';
export class Validator {
schema;
draft;
shortCircuit;
lookup;
constructor(schema, draft = '2019-09', shortCircuit = true) {
this.schema = schema;
this.draft = draft;
this.shortCircuit = shortCircuit;
this.lookup = dereference(schema);
}
validate(instance) {
return validate(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
}
addSchema(schema, id) {
if (id) {
schema = { ...schema, $id: id };
}
dereference(schema, this.lookup);
}
}