Provides a DSL for booleans.
Provides a DSL for collection-like objects.
Wraps expressions under validation with the Accord DSL.
Enables explicitly describing expression under validation.
Provides a DSL for untyped validators.
A structural type representing any object that has a size.
A structural type representing any object that has a size.
Provides a DSL for types with a corresponding implmentation of scala.math.Ordering.
Provides a DSL for string validators.
Extends validators with useful helpers.
Generates a validator that succeeds only if the provided value is less than the specified bound.
Generates a validator that succeeds only if the provided value is less than the specified bound.
Generates a validator that succeeds if the provided value is less than or equal to the specified bound.
Generates a validator that succeeds if the provided value is less than or equal to the specified bound.
Generates a validator that succeeds if the provided value is exactly equal to the specified value.
Generates a validator that succeeds if the provided value is exactly equal to the specified value.
Generates a validator that succeeds only if the provided value is greater than the specified bound.
Generates a validator that succeeds only if the provided value is greater than the specified bound.
Generates a validator that succeeds if the provided value is greater than or equal to the specified bound.
Generates a validator that succeeds if the provided value is greater than or equal to the specified bound.
Stubs for forwards compatibility with 2.
Specifies a validator that succeeds only if the validation expression is null.
Specifies a validator that succeeds only if the validation expression is null.
Specifies a validator that succeeds only if the validation expression evaluates to the specified type.
Specifies a validator that succeeds only if the validation expression evaluates to the specified type. Respects nulls.
Provides the "be" keyword.
Provides the "be" keyword.
Makes all members of OrderingOps accessible via the following syntax:
p.age should be > 5`
com.wix.accord.dsl.OrderingOps
Generates a validator that succeeds if the provided value is between (inclusive) the specified bounds.
Generates a validator that succeeds if the provided value is between (inclusive) the specified bounds.
The method exclusive
is provided to specify an exclusive upper bound.
An implicit conversion from boolean to a respective IsTrue
/IsFalse
instance; this enables syntax
such as customer.emailOptIn is true
.
An implicit conversion from boolean to a respective IsTrue
/IsFalse
instance; this enables syntax
such as customer.emailOptIn is true
.
Specifies a validator that fails on collections with duplicate elements.
Specifies a validator that fails on collections with duplicate elements.
Specifies a validator that succeeds on empty instances; the object under validation must implement
def isEmpty: Boolean
(see com.wix.accord.combinators.HasEmpty).
Specifies a validator that succeeds on empty instances; the object under validation must implement
def isEmpty: Boolean
(see com.wix.accord.combinators.HasEmpty).
Specifies a validator that operates on strings and succeeds only if the validation expression ends with the specified suffix.
Specifies a validator that operates on strings and succeeds only if the validation expression ends with the specified suffix.
Specifies a validator that succeeds only if the validation expression is equal to the specified value.
Specifies a validator that succeeds only if the validation expression is equal to the specified value. Respects nulls an performs equality checks via java.lang.Object.equals.
An implicit conversion to enable any collection-like object (e.
An implicit conversion to enable any collection-like object (e.g. strings, options) to be handled by com.wix.accord.dsl.CollectionDslContext.
java.lang.String does not directly implement size
(in practice it is implemented in
scala.collection.IndexedSeqOptimized via an implicit conversion and an inheritance stack), and this is
a case where the Scala compiler does not always infer structural types correctly. By requiring
a view bound from T
to scala.collection.GenTraversableOnce we can force any collection-like structure
to conform to the structural type com.wix.accord.dsl.CollectionOps.HasSize, and by requiring
a view bound from T
to com.wix.accord.dsl.CollectionOps.HasSize at the call site (via
com.wix.accord.dsl.CollectionDslContext) we additionally support any class that directly
conforms to the structural type as well.
The type that conforms, directly or implicitly, to com.wix.accord.dsl.CollectionOps.HasSize.
An object that is, or is implicitly convertible to, scala.collection.GenTraversableOnce.
The specified object, strictly-typed as com.wix.accord.dsl.CollectionOps.HasSize.
Specifies a validator that succeeds only if the object exists in the specified set of items.
Specifies a validator that succeeds only if the object exists in the specified set of items.
Specifies a validator that succeeds only if the object exists in the specified set.
Specifies a validator that succeeds only if the object exists in the specified set.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.
Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.
Specifies a validator that fails only if the validation expression evaluates to the specified type.
Specifies a validator that fails only if the validation expression evaluates to the specified type. Respects nulls.
Specifies a validator that fails on empty instances; the object under validation must implement
def isEmpty: Boolean
(see com.wix.accord.combinators.HasEmpty).
Specifies a validator that fails on empty instances; the object under validation must implement
def isEmpty: Boolean
(see com.wix.accord.combinators.HasEmpty).
Specifies a validator that succeeds only if the validation expression is not equal to the specified value.
Specifies a validator that succeeds only if the validation expression is not equal to the specified value. Respects nulls an performs equality checks via java.lang.Object.equals.
Specifies a validator that succeeds only if the validation expression is not null.
Specifies a validator that succeeds only if the validation expression is not null.
Provides access to size-based validators (where the object under validation must implement
def size: Int
, see com.wix.accord.dsl.CollectionOps.HasSize).
Provides access to size-based validators (where the object under validation must implement
def size: Int
, see com.wix.accord.dsl.CollectionOps.HasSize). Enables syntax such as
c.students has size > 0
.
Specifies a validator that operates on strings and succeeds only if the validation expression starts with the specified prefix.
Specifies a validator that operates on strings and succeeds only if the validation expression starts with the specified prefix.
Delegates validation to a pre-defined validation rule, which is encoded as an implicit com.wix.accord.Validator in scope.
Delegates validation to a pre-defined validation rule, which is encoded as an implicit com.wix.accord.Validator in scope. Enables composition of validation rules, as in:
case class Address( address1: String, address2: String, city: String, ... )
case class Item( sku: String, count: Int, ... )
case class Shipment( items: Seq[ Item ], address: Location, ... )
implicit val addressValidator = validator[ Address ] { ... } implicit val itemValidator = validator[ Item ] { ... }
implicit val shipmentValidator = validator[ Shipment ] { shipment => shipment.address is valid // Implicitly uses addressValidator shipment.items.each is valid // Implicitly uses itemValidator }
Defines a new validator for the specified type.
Defines a new validator for the specified type.
This function takes a block of validation rules (encoded as a "thunk"), and rewrites them as a full-fledged instance of Validator. A full example and details of the available syntax can be found in the package documentation.
Details of the code transformation are documented in ValidationTransform (fair warning: this description is quite low-level and fairly involved, and will likely not be of interest to most users).
The type under validation.
The validation code block; may contain any combination of validation statements.
The validation code block rewritten as a com.wix.accord.Validator for the specified type T
.
com.wix.accord.dsl
Generates a validator that succeeds if the provided value is within the specified range.
Generates a validator that succeeds if the provided value is within the specified range.
Generates a validator that succeeds if the provided value is within the specified range.
Generates a validator that succeeds if the provided value is within the specified range.
Provides a DSL for defining validation rules.
Overview
Accord provides a convenient DSL for defining validation rules. To define a validator over some type
T
, import this package and invoke validator[T]. You can then use the provided sample object to define various rules:Accord adds an implicit logical
and
relation between the rules, so all rules must apply in order for the validation to be successful. You can specify as many rules as you like.Descriptions
Each validation rule has an associated description (accessible via com.wix.accord.Violation.description). This description is automatically generated by Accord:
You can also explicitly provide a description with the "as" modifier:
Combinators
Accord offers a built-in library of building blocks (called "combinators") that can be composed into more complex validation rules:
General-purpose
Primitives
Collections
Boolean Expressions