Validator
open class Validator
Validates values against Constraint
s on Group
s or GroupSequence
with Validator.Options
.
-
Initializes a new instance.
Declaration
Swift
public init()
-
Validates a primitive
Encodable
value against an array ofConstraint
s on a set ofGroup
s.Throws
AValidator.Error
if the value is not of primitive type or aConstraintViolation
if the value doesn’t satisfyConstraint
s onGroup
s.Declaration
Swift
public func validate( _ value: Encodable?, against constraints: [Constraint], on groups: Set<Group> = .init() ) throws
Parameters
value
A primitive
Encodable
value to be validated.constraints
An array of
Constraint
s.groups
A set of
Group
s to run validations for. Defaults to an empty set. -
Validates a primitive
Encodable
value against a variadic list ofConstraint
s on a set ofGroup
s.Throws
AValidator.Error
if the value is not of primitive type or aConstraintViolation
if the value doesn’t satisfyConstraint
s onGroup
s.Declaration
Swift
public func validate( _ value: Encodable?, against constraints: Constraint..., on groups: Set<Group> = .init() ) throws
Parameters
value
A primitive
Encodable
value to be validated.constraints
A variadic list of
Constraint
s.groups
A set of
Group
s to run validations for. Defaults to an empty set. -
Validates a primitive
Encodable
value against an array ofConstraintType
s on a set ofGroup
s.Throws
AValidator.Error
if the value is not of primitive type or aConstraintViolation
if the value doesn’t satisfyConstraint
s onGroup
s.Declaration
Swift
public func validate( _ value: Encodable?, against constraintTypes: [ConstraintType], on groups: Set<Group> = .init() ) throws
Parameters
value
A primitive
Encodable
value to be validated.constraintTypes
An array of
ConstraintType
s.groups
A set of
Group
s to run validations for. Defaults to an empty set. -
Validates a complex
Encodable
value against aDictionaryCollection<String, Constraint>
on a set ofGroup
s with a list ofValidator.Options
.Throws
AValidator.Error
if it can’t decode the encoded value.Declaration
Swift
public func validate( _ value: Encodable?, against constraintCollection: DictionaryCollection<String, Constraint>, on groups: Set<Group> = .init(), with options: Options = .init() ) throws -> DictionaryCollection<String, ConstraintViolation>
Parameters
value
A complex
Encodable
value to be validated.constraintCollection
A
DictionaryCollection<String, Constraint>
.groups
A set of
Group
s to run validations for. Defaults to an empty set.options
A list of
Validator.Options
. Defaults to an empty array.Return Value
A
DictionaryCollection<String, ConstraintViolation>
. -
Validates a complex
Encodable
value against aDictionaryCollection<String, Constraint>
on aGroupSequence
with a list ofValidator.Options
.Throws
AValidator.Error
if it can’t decode the encoded value.Declaration
Swift
public func validate( _ value: Encodable?, against constraintCollection: DictionaryCollection<String, Constraint>, on groupSequence: GroupSequence, with options: Options = .init() ) throws -> DictionaryCollection<String, ConstraintViolation>
Parameters
value
A complex
Encodable
value to be validated.constraintCollection
A
DictionaryCollection<String, Constraint>
.groupSequence
A list of groups.
options
A list of
Validator.Options
. Defaults to an empty array.Return Value
A
DictionaryCollection<String, ConstraintViolation>
. -
A common error type thrown when an invalid
See moreConstraint
type is provided to thevalidate(_:against:)
method of theConstraintValidator
.Declaration
Swift
public enum Error : LocalizedError