Validator

sttp.tapir.Validator
See theValidator companion trait
object Validator extends ValidatorMacros

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Validator.type

Members list

Type members

Classlikes

case class All[T](validators: Seq[Validator[T]]) extends Validator[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Validator[T]
class Object
trait Matchable
class Any
Show all
case class Any[T](validators: Seq[Validator[T]]) extends Validator[T]

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait Validator[T]
class Object
trait Matchable
class Any
Show all
object Any

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Any.type
case class Custom[T](validationLogic: T => ValidationResult, showMessage: Option[String]) extends Primitive[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
case class Enumeration[T](possibleValues: List[T], encode: Option[() => T], name: Option[SName]) extends Primitive[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
case class Mapped[TT, T](wrapped: Validator[T], g: TT => T) extends Validator[TT]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Validator[TT]
class Object
trait Matchable
class Any
Show all
case class Max[T](value: T, exclusive: Boolean)(implicit valueIsNumeric: Numeric[T]) extends Primitive[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
case class MaxLength[T <: String](value: Int, countCodePoints: Boolean) extends Primitive[T]

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
object MaxLength

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
MaxLength.type
case class MaxSize[T, C <: (Iterable)](value: Int) extends Primitive[C[T]]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[C[T]]
trait Validator[C[T]]
class Object
trait Matchable
class Any
Show all
case class Min[T](value: T, exclusive: Boolean)(implicit valueIsNumeric: Numeric[T]) extends Primitive[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
case class MinLength[T <: String](value: Int, countCodePoints: Boolean) extends Primitive[T]

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
object MinLength

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
MinLength.type
case class MinSize[T, C <: (Iterable)](value: Int) extends Primitive[C[T]]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[C[T]]
trait Validator[C[T]]
class Object
trait Matchable
class Any
Show all
case class Pattern[T <: String](value: String) extends Primitive[T]

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Primitive[T]
trait Validator[T]
class Object
trait Matchable
class Any
Show all
sealed trait Primitive[T] extends Validator[T]

Attributes

Supertypes
trait Validator[T]
class Object
trait Matchable
class Any
Known subtypes
class Custom[T]
class Enumeration[T]
class Max[T]
class MaxLength[T]
class MaxSize[T, C]
class Min[T]
class MinLength[T]
class MinSize[T, C]
class Pattern[T]
Show all

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](validationLogic: T => ValidationResult, showMessage: Option[String]): Validator[T]

Create a custom validator.

Create a custom validator.

Value parameters

showMessage

Description of the validator used when invoking Validator.show.

validationLogic

The logic of the validator

Attributes

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

Attributes

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 parameters

encode

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

Attributes

def fixedLength[T <: String](value: Int): Validator[T]

Create a validator for fixed length constraints on strings.

Create a validator for fixed length constraints on strings.

Value parameters

value

The fixed allowed length.

Attributes

def fixedLength[T <: String](value: Int, countCodePoints: Boolean): Validator[T]

Create a validator for fixed length constraints on strings.

Create a validator for fixed length constraints on strings.

Value parameters

countCodePoints

A boolean parameter that determines whether the validation will consider code points or character count. When set to true, the validator will consider characters that are represented using two code units (a surrogate pair) in UTF-16 encoding allowing for a more accurate length validation for strings containing such characters (like emojis). Defaults to false, where length is validated based on the number of Char values in the string.

value

The fixed allowed length.

Attributes

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]

Create a validator for maximum length constraints on strings.

Create a validator for maximum length constraints on strings.

Value parameters

value

The maximum allowed length.

Attributes

def maxLength[T <: String](value: Int, countCodePoints: Boolean): Primitive[T]

Create a validator for maximum length constraints on strings.

Create a validator for maximum length constraints on strings.

Value parameters

countCodePoints

A boolean parameter that determines whether the validation will consider code points or character count. When set to true, the validator will consider characters that are represented using two code units (a surrogate pair) in UTF-16 encoding allowing for a more accurate length validation for strings containing such characters (like emojis). Defaults to false, where length is validated based on the number of Char values in the string.

value

The maximum allowed length.

Attributes

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]

Create a validator for minimum length constraints on strings.

Create a validator for minimum length constraints on strings.

Value parameters

value

The minimum allowed length.

Attributes

def minLength[T <: String](value: Int, countCodePoints: Boolean): Primitive[T]

Create a validator for minimum length constraints on strings.

Create a validator for minimum length constraints on strings.

Value parameters

countCodePoints

A boolean parameter that determines whether the validation will consider code points or character count. When set to true, the validator will consider characters that are represented using two code units (a surrogate pair) in UTF-16 encoding allowing for a more accurate length validation for strings containing such characters (like emojis). Defaults to false, where length is validated based on the number of Char values in the string.

value

The minimum allowed length.

Attributes

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.

Attributes

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.

Attributes

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

Inherited methods

inline def derivedEnumeration[T]: Enumeration[T]

Creates an enum validator for an enum where all cases are parameterless, or 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 for an enum where all cases are parameterless, or 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).

Attributes

Inherited from:
ValidatorMacros