Validator
Validator.swift:1struct Validator<T> where T : Decodable, T : Sendable
struct Validator<T> where T : Decodable, T : Sendable
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
protocol Decodable
A type that can decode itself from an external representation.
protocol Sendable
@preconcurrency init(validate: @escaping (_ data: T) -> ValidatorResult)
let validate: (_ data: T) -> ValidatorResult
protocol OptionalType : AnyOptionalType
Capable of being represented by an optional wrapped type.
static var `nil`: Validator<T> { get }
Validates that the data is nil
. Combine with the not-operator !
to validate that the data is not nil
.
protocol Comparable : Equatable
A type that can be compared using the relational operators <
, <=
, >=
, and >
.
static func range(_ range: ClosedRange<T>) -> Validator<T>
Validates that the data is within the supplied ClosedRange
.
static func range(_ range: PartialRangeFrom<T>) -> Validator<T>
Validates that the data is greater than or equal the supplied lower bound using PartialRangeFrom
.
static func range(_ range: PartialRangeThrough<T>) -> Validator<T>
Validates that the data is less than or equal to the supplied upper bound using PartialRangeThrough
.
protocol Equatable
A type that can be compared for value equality.
protocol CustomStringConvertible
A type with a customized textual representation.
static func `in`<S>(_ sequence: S) -> Validator<T> where T == S.Element, S : Sendable, S : Sequence
Validates whether an item is contained in the supplied sequence.
static func `in`(_ array: T...) -> Validator<T>
Validates whether an item is contained in the supplied array.
protocol SignedInteger : BinaryInteger, SignedNumeric
An integer type that can represent both positive and negative values.
static func range(_ range: PartialRangeUpTo<T>) -> Validator<T>
Validates that the data is less than the supplied upper bound using PartialRangeUpTo
protocol Collection<Element> : Sequence
A sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
static var empty: Validator<T> { get }
Validates that the data is empty. You can also check a non empty state by negating this validator: !.empty
.
static func count(_ range: ClosedRange<Int>) -> Validator<T>
Validates that the data’s count is within the supplied ClosedRange
.
static func count(_ range: Swift.Range<Int>) -> Validator<T>
Validates that the data’s count is within the supplied Range
.
static func count(_ range: PartialRangeFrom<Int>) -> Validator<T>
Validates that the data’s count is greater than or equal to the supplied lower bound using PartialRangeFrom
.
static func count(_ range: PartialRangeUpTo<Int>) -> Validator
Validates that the data’s count is less than the supplied upper bound using PartialRangeUpTo
.
static func count(_ range: PartialRangeThrough<Int>) -> Validator<T>
Validates that the data’s count is less than or equal the supplied upper bound using PartialRangeThrough
.
protocol Strideable<Stride> : Comparable
A type representing continuous, one-dimensional values that can be offset and measured.
static func range(_ range: Swift.Range<T>) -> Validator<T>
Validates that the data is within the supplied Range
.
static var valid: Validator<T> { get }
Validates nothing. Can be used as placeholder to validate successful decoding
static func `case`<E>(of enum: E.Type) -> Validator<T> where T : CustomStringConvertible, T == E.RawValue, E : CaseIterable, E : RawRepresentable
Validates that the data can be converted to a value of an enum type with iterable cases.
static func custom(_ validationDescription: String, validationClosure: @escaping (T) -> Bool) -> Validator<T>
Validates whether a String
matches a RegularExpression pattern
@frozen struct String
A Unicode string value that is a collection of characters.
static var alphanumeric: Validator { get }
Validates that all characters in a String
are alphanumeric (a-z,A-Z,0-9).
static var ascii: Validator { get }
Validates that all characters in a String
are ASCII (bytes 0..<128).
static var email: Validator<T> { get }
Validates whether a String
is a valid email address.
static var internationalEmail: Validator<T> { get }
static var url: Validator<T> { get }
Validates whether a String
is a valid URL.
static func characterSet(_ characterSet: Foundation.CharacterSet) -> Validator
Validates that all characters in a String
are in the supplied CharacterSet
.
static func pattern(_ pattern: String) -> Validator<T>
Validates whether a String
matches a RegularExpression pattern
@frozen struct Array<Element>
An ordered, random-access collection.
static var alphanumeric: Validator { get }
Validates that all characters in elements of a [String]
are alphanumeric (a-z,A-Z,0-9).
static var ascii: Validator { get }
Validates that all characters in elements of a [String]
are ASCII (bytes 0..<128).
static func characterSet(_ characterSet: Foundation.CharacterSet) -> Validator
Validates that all characters in elements of a [String]
are in the supplied CharacterSet
.