terrazza/validator

Terrazza Component Validator

1.0.2 2022-05-22 22:00 UTC

This package is auto-updated.

Last update: 2024-04-23 02:05:56 UTC


README

This component validates/approves content against schemas

Object/Classes

  1. ObjectValueSchema
  2. ObjectValidator

ObjectValueSchema

Properties:

  • name (string, required)
  • type (string, required)
    • number
    • integer
    • double
    • array
    • boolean
    • string
    • object
    • oneOf (require setChildSchemas)
  • required (bool, default=false)
  • nullable (bool, default=false)
  • patterns (string, optional)
    only used for type: string
  • format (string, optional)
    only used for type: string
  • minLength (int, optional)
    only used for type: number, integer, double
  • maxLength (int, optional)
    only used for type: number, integer, double
  • minItems (int, optional)
    only used for type: array
  • maxItems (int, optional)
    only used for type: array
  • minRange (float, optional)
    only used for type: number, integer, double
  • maxRange (float, optional)
    only used for type: number, integer, double
  • multipleOf (float, optional)
    only used for type: number, integer, double
  • enum (scalar, optional)
    only used for type: number, integer, double
  • childSchemas (arrayOf ObjectValueSchema, optional)

method: isMultipleType

verifies if the type is one of

  • oneOf

ObjectValidator

method: isValid

calls method::validate but covered in a try/catch.
In case of catch the method returns false. Otherwise, the method returns true.

method: validate

Validate the content against

  • contentType
  • validateArray
  • validateString
  • validateNumber
  • validateFormat
  • validateEnum
  • validateMultipleTypes (e.g. oneOf)

method: getEncodedValue

Method try to solve some content : schema mismatches that could be solved.
In case of being able to solve a mismatch, the method

  • set the type of the schema to the converted one
  • returns the converted value

Examples

  • expected type: integer, given "12"
  • expected type: boolean, given "yes"