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

Method validateSchema

docs/scripts/ajv-validator.js:3764–3787  ·  view source on GitHub ↗
(schema, throwOrLogError)

Source from the content-addressed store, hash-verified

3762 }
3763 // Validate schema against its meta-schema
3764 validateSchema(schema, throwOrLogError) {
3765 if (typeof schema == "boolean")
3766 return true;
3767 let $schema;
3768 $schema = schema.$schema;
3769 if ($schema !== undefined && typeof $schema != "string") {
3770 throw new Error("$schema must be a string");
3771 }
3772 $schema = $schema || this.opts.defaultMeta || this.defaultMeta();
3773 if (!$schema) {
3774 this.logger.warn("meta-schema not available");
3775 this.errors = null;
3776 return true;
3777 }
3778 const valid = this.validate($schema, schema);
3779 if (!valid && throwOrLogError) {
3780 const message = "schema is invalid: " + this.errorsText();
3781 if (this.opts.validateSchema === "log")
3782 this.logger.error(message);
3783 else
3784 throw new Error(message);
3785 }
3786 return valid;
3787 }
3788 // Get compiled schema by `key` or `ref`.
3789 // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)
3790 getSchema(keyRef) {

Callers 3

_addSchemaMethod · 0.95
macroKeywordCodeFunction · 0.80
validateKeywordUsageFunction · 0.80

Calls 4

defaultMetaMethod · 0.95
validateMethod · 0.95
errorsTextMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected