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

Method validate

lib/core.ts:355–371  ·  view source on GitHub ↗
(
    schemaKeyRef: AnySchema | string, // key, ref or schema object
    // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
    data: unknown | T // to be validated
  )

Source from the content-addressed store, hash-verified

353 validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T>
354 validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T>
355 validate<T>(
356 schemaKeyRef: AnySchema | string, // key, ref or schema object
357 // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
358 data: unknown | T // to be validated
359 ): boolean | Promise<T> {
360 let v: AnyValidateFunction | undefined
361 if (typeof schemaKeyRef == "string") {
362 v = this.getSchema<T>(schemaKeyRef)
363 if (!v) throw new Error(`no schema with key or ref "${schemaKeyRef}"`)
364 } else {
365 v = this.compile<T>(schemaKeyRef)
366 }
367
368 const valid = v(data)
369 if (!("$async" in v)) this.errors = v.errors
370 return valid
371 }
372
373 // Create validation function for passed schema
374 // _meta: true if schema is a meta-schema. Used internally to compile meta schemas of user-defined keywords.

Callers 15

validateSchemaMethod · 0.95
resolve.spec.tsFile · 0.45
ajv.spec.tsFile · 0.45
coercion.spec.tsFile · 0.45
testCoercionFunction · 0.45
assertValidFunction · 0.45
assertInvalidFunction · 0.45
keyword.spec.tsFile · 0.45
jtd-schema.spec.tsFile · 0.45
jtd-schema.spec.tsFile · 0.45
testFunction · 0.45

Calls 2

getSchemaMethod · 0.95
compileMethod · 0.95

Tested by 7

testCoercionFunction · 0.36
assertValidFunction · 0.36
assertInvalidFunction · 0.36
testFunction · 0.36
testFunction · 0.36
specFunction · 0.36
specFunction · 0.36