Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SchemaValidator

Loads a JSON schema and performs validations against JSON objects.

Hierarchy

  • SchemaValidator

Index

Constructors

Methods

Constructors

constructor

  • 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 from which the schema with which to validate should be loaded.

    Returns SchemaValidator

Methods

load

  • load(): Promise<JsonMap>
  • Loads a JSON schema from the schemaPath parameter provided at instantiation.

    Returns Promise<JsonMap>

validate

  • validate(json: AnyJson): Promise<AnyJson>
  • Performs validation of JSON data against the schema located at the schemaPath value provided at instantiation.

    Throws SfdxError{ name: 'ValidationSchemaFieldErrors' } If there are known validations errors. Throws SfdxError{ name: 'ValidationSchemaUnknown' } 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.