Validator

object Validator extends ValidatorMacros
Companion
class
class Object
trait Matchable
class Any

Type members

Classlikes

case
class All[T](validators: Seq[Validator[T]]) extends Validator[T]
case
class Any[T](validators: Seq[Validator[T]]) extends Validator[T]
case
class Custom[T](doValidate: T => List[ValidationError[_]], showMessage: Option[String]) extends Validator[T]
case
class Enumeration[T](possibleValues: List[T], encode: Option[() => T], name: Option[SName]) extends Primitive[T]
case
class Mapped[TT, T](wrapped: Validator[T], g: TT => T) extends Validator[TT]
case
class Max[T](value: T, exclusive: Boolean)(implicit valueIsNumeric: Numeric[T]) extends Primitive[T]
case
class MaxLength[T <: String](value: Int) extends Primitive[T]
case
class MaxSize[T, C <: ([_] =>> Iterable[_])](value: Int) extends Primitive[C[T]]
case
class Min[T](value: T, exclusive: Boolean)(implicit valueIsNumeric: Numeric[T]) extends Primitive[T]
case
class MinLength[T <: String](value: Int) extends Primitive[T]
case
class MinSize[T, C <: ([_] =>> Iterable[_])](value: Int) extends Primitive[C[T]]
case
class Pattern[T <: String](value: String) extends Primitive[T]
sealed
trait Primitive[T] extends Validator[T]

Types

type EncodeToRaw[T] = T => Option[Any]

Value members

Concrete methods

def all[T](v: Validator[T]*): Validator[T]
def any[T](v: Validator[T]*): Validator[T]
def custom[T](doValidate: T => List[ValidationError[_]], showMessage: Option[String]): Validator[T]

Create a custom validator

Create a custom validator

Value Params
doValidate

Validation function

showMessage

Custom message

def enumeration[T](possibleValues: List[T]): Enumeration[T]

Create an enumeration validator, with the given possible values.

Create an enumeration validator, with the given possible values.

To represent the enumerated values in documentation, an encoding function needs to be provided. This can be done: * by using the overloaded enumeration method with an encode parameter * by adding an encode function on an Validator.Enumeration instance using one of the .encode functions * by adding the validator directly to a codec (see Mapping.addEncodeToEnumValidator * when the values possible values are of a basic type (numbers, strings), the encode function is inferred if not present, when being added to the schema, see Schema.validate

def enumeration[T](possibleValues: List[T], encode: () => T, name: Option[SName]): Enumeration[T]

Create an enumeration validator, with the given possible values, an optional encoding function (so that the enumerated values can be represented in documentation), and an optional name (to create a reusable documentation component).

Create an enumeration validator, with the given possible values, an optional encoding function (so that the enumerated values can be represented in documentation), and an optional name (to create a reusable documentation component).

Value Params
encode

Specify how values of this type can be encoded to a raw value, which will be used for documentation.

def fixedLength[T <: String](value: Int): Validator[T]
def fixedSize[T, C <: ([_] =>> Iterable[_])](value: Int): Validator[C[T]]
def inRange[T : Numeric](min: T, max: T, minExclusive: Boolean, maxExclusive: Boolean): Validator[T]
def max[T : Numeric](value: T, exclusive: Boolean): Primitive[T]
def maxLength[T <: String](value: Int): Primitive[T]
def maxSize[T, C <: ([_] =>> Iterable[_])](value: Int): Primitive[C[T]]
def min[T : Numeric](value: T, exclusive: Boolean): Primitive[T]
def minLength[T <: String](value: Int): Primitive[T]
def minSize[T, C <: ([_] =>> Iterable[_])](value: Int): Primitive[C[T]]
def negative[T : Numeric]: Primitive[T]
def nonEmpty[T, C <: ([_] =>> Iterable[_])]: Primitive[C[T]]
def nonEmptyString[T <: String]: Primitive[T]
def pass[T]: Validator[T]

A validator instance that always pass.

A validator instance that always pass.

def pattern[T <: String](value: String): Primitive[T]
def positive[T : Numeric]: Primitive[T]
def positiveOrZero[T : Numeric]: Primitive[T]
def reject[T]: Validator[T]

A validator instance that always reject.

A validator instance that always reject.

def show[T](v: Validator[T]): Option[String]

Inherited methods

Creates an enum validator where all subtypes of the sealed hierarchy T are objects. This enumeration will only be used for documentation, as a value outside of the allowed values will not be decoded in the first place (the decoder has no other option than to fail).

Creates an enum validator where all subtypes of the sealed hierarchy T are objects. This enumeration will only be used for documentation, as a value outside of the allowed values will not be decoded in the first place (the decoder has no other option than to fail).

Inherited from
ValidatorMacros