Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Ajv

Hierarchy

  • Ajv

Index

Properties

Optional errors

errors: Array<ErrorObject> | null

Methods

addFormat

  • Add custom format

    Parameters

    Returns Ajv

    this for method chaining

addKeyword

  • Define custom keyword

    this

    Ajv

    Parameters

    • keyword: string

      custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.

    • definition: KeywordDefinition

      keyword definition object with properties type (type(s) which the keyword applies to), validate or compile.

    Returns Ajv

    this for method chaining

addMetaSchema

  • addMetaSchema(schema: object, key?: undefined | string): Ajv
  • Add schema that will be used to validate other schemas options in META_IGNORE_OPTIONS are alway set to false

    Parameters

    • schema: object

      schema object

    • Optional key: undefined | string

      optional schema key

    Returns Ajv

    this for method chaining

addSchema

  • addSchema(schema: Array<object> | object, key?: undefined | string): Ajv
  • Adds schema to the instance.

    Parameters

    • schema: Array<object> | object

      schema or array of schemas. If array is passed, key and other parameters will be ignored.

    • Optional key: undefined | string

      Optional schema key. Can be passed to validate method instead of schema object or id/ref. One schema per instance can have empty id and key.

    Returns Ajv

    this for method chaining

compile

  • Create validating function for passed schema.

    Parameters

    • schema: object | boolean

      schema object

    Returns ValidateFunction

    validating function

compileAsync

  • Creates validating function for passed schema with asynchronous loading of missing schemas. loadSchema option should be a function that accepts schema uri and node-style callback.

    this

    Ajv

    Parameters

    • schema: object | boolean

      schema object

    • Optional meta: Boolean

      optional true to compile meta-schema; this parameter can be skipped

    • Optional callback: undefined | ((err: Error, validate: ValidateFunction) => any)

      optional node-style callback, it is always called with 2 parameters: error (or null) and validating function.

    Returns PromiseLike<ValidateFunction>

    validating function

errorsText

  • Convert array of error message objects to string

    Parameters

    • Optional errors: Array<ErrorObject> | null

      optional array of validation errors, if not passed errors from the instance are used.

    • Optional options: ErrorsTextOptions

      optional options with properties separator and dataVar.

    Returns string

    human readable string with all errors descriptions

getKeyword

  • getKeyword(keyword: string): object | boolean
  • Get keyword definition

    this

    Ajv

    Parameters

    • keyword: string

      pre-defined or custom keyword.

    Returns object | boolean

    custom keyword definition, true if it is a predefined keyword, false otherwise.

getSchema

  • Get compiled schema from the instance by key or ref.

    Parameters

    • keyRef: string

      key that was passed to addSchema or full schema reference (schema.id or resolved id).

    Returns ValidateFunction

    schema validating function (with property schema).

removeKeyword

  • removeKeyword(keyword: string): Ajv
  • Remove keyword

    this

    Ajv

    Parameters

    • keyword: string

      pre-defined or custom keyword.

    Returns Ajv

    this for method chaining

removeSchema

  • removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv
  • Remove cached schema(s). If no parameter is passed all schemas but meta-schemas are removed. If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed. Even if schema is referenced by other schemas it still can be removed as other schemas have local references.

    Parameters

    • Optional schemaKeyRef: object | string | RegExp | boolean

      key, ref, pattern to match key/ref or schema object

    Returns Ajv

    this for method chaining

validate

  • validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>
  • Validate data using schema Schema will be compiled and cached (using serialized JSON as key, fast-json-stable-stringify is used to serialize by default).

    Parameters

    • schemaKeyRef: object | string | boolean

      key, ref or schema object

    • data: any

      to be validated

    Returns boolean | PromiseLike<any>

    validation result. Errors from the last validation will be available in ajv.errors (and also in compiled schema: schema.errors).

validateKeyword

  • Validate keyword

    this

    Ajv

    Parameters

    • definition: KeywordDefinition

      keyword definition object

    • throwError: boolean

      true to throw exception if definition is invalid

    Returns boolean

    validation result

validateSchema

  • validateSchema(schema: object | boolean): boolean
  • Validate schema

    Parameters

    • schema: object | boolean

      schema to validate

    Returns boolean

    true if schema is valid