MCPcopy Create free account
hub / github.com/json-editor/json-editor / validate

Method validate

docs/scripts/ajv-validator.js:3658–3674  ·  view source on GitHub ↗
(schemaKeyRef, // key, ref or schema object
                         data // to be validated
                )

Source from the content-addressed store, hash-verified

3656 return (this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : undefined);
3657 }
3658 validate(schemaKeyRef, // key, ref or schema object
3659 data // to be validated
3660 ) {
3661 let v;
3662 if (typeof schemaKeyRef == "string") {
3663 v = this.getSchema(schemaKeyRef);
3664 if (!v)
3665 throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
3666 }
3667 else {
3668 v = this.compile(schemaKeyRef);
3669 }
3670 const valid = v(data);
3671 if (!("$async" in v))
3672 this.errors = v.errors;
3673 return valid;
3674 }
3675 compile(schema, _meta) {
3676 const sch = this._addSchema(schema, _meta);
3677 return (sch.validate || this._compileSchemaEnv(sch));

Callers 1

validateSchemaMethod · 0.95

Calls 2

getSchemaMethod · 0.95
compileMethod · 0.95

Tested by

no test coverage detected