mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
2205d64ea3
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
24 lines
657 B
JavaScript
24 lines
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);
|
|
}
|
|
}
|