validator.js 657 B

1234567891011121314151617181920212223
  1. import { dereference } from './dereference.js';
  2. import { validate } from './validate.js';
  3. export class Validator {
  4. schema;
  5. draft;
  6. shortCircuit;
  7. lookup;
  8. constructor(schema, draft = '2019-09', shortCircuit = true) {
  9. this.schema = schema;
  10. this.draft = draft;
  11. this.shortCircuit = shortCircuit;
  12. this.lookup = dereference(schema);
  13. }
  14. validate(instance) {
  15. return validate(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
  16. }
  17. addSchema(schema, id) {
  18. if (id) {
  19. schema = { ...schema, $id: id };
  20. }
  21. dereference(schema, this.lookup);
  22. }
  23. }