Loads a JSON schema and performs validations against JSON objects.

Hierarchy

  • SchemaValidator

Constructors

  • Creates a new SchemaValidator instance given a logger and path to a schema file.

    Parameters

    • logger: Logger

      An Logger instance on which to base this class's logger.

    • schemaPath: string

      The path to the schema file to load and use for validation.

    Returns SchemaValidator

Methods

  • Loads a JSON schema from the schemaPath parameter provided at instantiation.

    Returns Promise<JsonMap>

  • Loads a JSON schema from the schemaPath parameter provided at instantiation.

    Returns JsonMap

  • Performs validation of JSON data against the schema located at the schemaPath value provided at instantiation.

    Throws SfError{ name: 'ValidationSchemaFieldError' } If there are known validations errors. Throws SfError{ name: 'ValidationSchemaUnknownError' } If there are unknown validations errors.

    Parameters

    • json: AnyJson

      A JSON value to validate against this instance's target schema.

    Returns Promise<AnyJson>

    The validated JSON data.

  • Performs validation of JSON data against the schema located at the schemaPath value provided at instantiation.

    Throws SfError{ name: 'ValidationSchemaFieldError' } If there are known validations errors. Throws SfError{ name: 'ValidationSchemaUnknownError' } If there are unknown validations errors.

    Type Parameters

    • T extends AnyJson

    Parameters

    • json: T

      A JSON value to validate against this instance's target schema.

    Returns T

    The validated JSON data.