Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "validate"

Module validate provides an implementation of JSON Typedef validation.

The most important function in this module is validate, which returns an array of ValidationError. You can configure validate by passing it a ValidationConfig.

Index

Functions

popInstanceToken

popSchemaToken

pushError

pushInstanceToken

pushSchemaToken

validate

  • validate performs JSON Typedef validation of an instance (or "input") against a JSON Typedef schema, returning a standardized set of errors.

    This function may throw MaxDepthExceededError if you have configured a ValidationConfig.maxDepth. If you do not configure such a maxDepth, then this function may cause a stack overflow. That's because of circularly-defined schemas like this one:

    {
      "ref": "loop",
      "definitions": {
        "loop": { "ref": "loop" }
      }
    }

    If your schema is not circularly defined like this, then there is no risk for validate to overflow the stack.

    If you are only interested in a certain number of error messages, consider using ValidationConfig.maxErrors to get better performance. For instance, if all you care about is whether the input is OK or if it has errors, you may want to set maxErrors to 1.

    Parameters

    • schema: Schema

      The schema to validate data against

    • instance: unknown

      The "input" to validate

    • Optional config: ValidationConfig

      Validation options. Optional.

    Returns ValidationError[]

validateInt

  • validateInt(state: ValidationState, instance: unknown, min: number, max: number): void

validateWithState

  • validateWithState(state: ValidationState, schema: Schema, instance: unknown, parentTag?: undefined | string): void

Generated using TypeDoc