Provides a DSL for booleans.
Provides a DSL for collection-like objects.
Provides a DSL for collection-like objects. Works in conjunction with com.wix.accord.dsl.DslContext.
Wraps expressions under validation with the Accord DSL.
Wraps expressions under validation with the Accord DSL.
This class provides the entry point into the DSL, by wrapping an expression with a specialized scope
(this is later used during the macro transform). This enables syntax such as p.firstName is notEmpty
,
where p.firstName
is the actual expression under validation.
See the package documentation for a full description of the DSL.
The type of the provided expression.
com.wix.accord.dsl
Enables explicitly describing expression under validation.
Enables explicitly describing expression under validation.
After the macro transform, the resulting validator will use the specified description to render violations. See the as method for full example.
The type of the provided expression.
com.wix.accord.dsl
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 types with a corresponding implmentation of scala.math.Ordering.
Implementation note: All methods here should only require scala.math.PartialOrdering, but the canonical implicits are defined in the Ordering companion and would therefore not be imported by default at the call site. This seems like a worthwhile trade-off.
Provides a DSL for string validators.
Extends validators with useful helpers.
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.
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.
Specifies a validator that operates on strings and succeeds only if the validation expression is blank (i.
Specifies a validator that operates on strings and succeeds only if the validation expression is blank (i.e. empty or whitespace-only).
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 operates on strings and succeeds only if the validation expression is not blank (i.
Specifies a validator that operates on strings and succeeds only if the validation expression is not blank (i.e. empty or whitespace-only).
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