MCPcopy
hub / github.com/ajv-validator/ajv / validateSchema

Method validateSchema

lib/core.ts:507–527  ·  view source on GitHub ↗
(schema: AnySchema, throwOrLogError?: boolean)

Source from the content-addressed store, hash-verified

505
506 // Validate schema against its meta-schema
507 validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown> {
508 if (typeof schema == "boolean") return true
509 let $schema: string | AnySchemaObject | undefined
510 $schema = schema.$schema
511 if ($schema !== undefined && typeof $schema != "string") {
512 throw new Error("$schema must be a string")
513 }
514 $schema = $schema || this.opts.defaultMeta || this.defaultMeta()
515 if (!$schema) {
516 this.logger.warn("meta-schema not available")
517 this.errors = null
518 return true
519 }
520 const valid = this.validate($schema, schema)
521 if (!valid && throwOrLogError) {
522 const message = "schema is invalid: " + this.errorsText()
523 if (this.opts.validateSchema === "log") this.logger.error(message)
524 else throw new Error(message)
525 }
526 return valid
527 }
528
529 // Get compiled schema by `key` or `ref`.
530 // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)

Callers 7

_addSchemaMethod · 0.95
macroKeywordCodeFunction · 0.80
validateKeywordUsageFunction · 0.80
ajv.spec.tsFile · 0.80
testOptionMetaFunction · 0.80

Calls 5

defaultMetaMethod · 0.95
validateMethod · 0.95
errorsTextMethod · 0.95
warnMethod · 0.80
errorMethod · 0.65

Tested by 2

testOptionMetaFunction · 0.64