Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MapSchema

Schema to validate maps.

Example

let schema = new MapSchema(TypeCode.String, TypeCode.Integer);

schema.validate({ "key1": "A", "key2": "B" });       // Result: no errors
schema.validate({ "key1": 1, "key2": 2 });           // Result: element type mismatch
schema.validate([ 1, 2, 3 ]);                        // Result: type mismatch

Hierarchy

Index

Constructors

constructor

  • Creates a new instance of validation schema and sets its values.

    see

    IValidationRule

    see

    TypeCode

    Parameters

    • Optional keyType: any

      a type of map keys. Null means that keys may have any type.

    • Optional valueType: any

      a type of map values. Null means that values may have any type.

    • Optional required: boolean

      (optional) true to always require non-null values.

    • Optional rules: IValidationRule[]

      (optional) a list with validation rules.

    Returns MapSchema

Methods

getKeyType

  • getKeyType(): any
  • Gets the type of map keys. Null means that keys may have any type.

    Returns any

    the type of map keys.

getRules

getValueType

  • getValueType(): any
  • Gets the type of map values. Null means that values may have any type.

    Returns any

    the type of map values.

isRequired

  • isRequired(): boolean
  • Gets a flag that always requires non-null values. For null values it raises a validation error.

    Returns boolean

    true to always require non-null values and false to allow null values.

makeOptional

  • Makes validated values optional. Validation for null values will be skipped.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    see

    makeRequired

    Returns Schema

    this validation schema

makeRequired

  • Makes validated values always required (non-null). For null values the schema will raise errors.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    see

    makeOptional

    Returns Schema

    this validation schema

Protected performTypeValidation

  • performTypeValidation(path: string, type: any, value: any, results: ValidationResult[]): void
  • Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or TypeCode When type is a Schema, it executes validation recursively against that Schema.

    see

    performValidation

    Parameters

    • path: string

      a dot notation path to the value.

    • type: any

      a type to match the value type

    • value: any

      a value to be validated.

    • results: ValidationResult[]

      a list with validation results to add new results.

    Returns void

Protected performValidation

  • performValidation(path: string, value: any, results: ValidationResult[]): void
  • Validates a given value against the schema and configured validation rules.

    Parameters

    • path: string

      a dot notation path to the value.

    • value: any

      a value to be validated.

    • results: ValidationResult[]

      a list with validation results to add new results.

    Returns void

setKeyType

  • setKeyType(value: any): void
  • Sets the type of map keys. Null means that keys may have any type.

    Parameters

    • value: any

      a type of map keys.

    Returns void

setRequired

  • setRequired(value: boolean): void
  • Sets a flag that always requires non-null values.

    Parameters

    • value: boolean

      true to always require non-null values and false to allow null values.

    Returns void

setRules

setValueType

  • setValueType(value: any): void
  • Sets the type of map values. Null means that values may have any type.

    Parameters

    • value: any

      a type of map values.

    Returns void

validate

validateAndReturnException

  • validateAndReturnException(correlationId: string, value: any, strict?: boolean): ValidationException

validateAndThrowException

  • validateAndThrowException(correlationId: string, value: any, strict?: boolean): void

withRule

  • Adds validation rule to this schema.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameters

    Returns Schema

    this validation schema.

Generated using TypeDoc