This is a Swift Vapor question related to the Vapor ValidationSuite and Validator.
My Class has a name variable. I used to declare name as a String. But I wanted to perform validation on this field. So I inherited the attributes of a validated Name field. See the following example code.
class Name: ValidationSuite {
static func validate(input value: String) throws {
let evaluation = OnlyAlphanumeric.self
&& Count.min(5)
&& Count.max(20)
try evaluation.validate(input: value)
}
}
The following code shows my class. Interesting points; this inherits from the Model class (as it connects to a database) and uses a Node for the ID. You can see I declared the name variable to conform to a Name type.
final class LedgerUser: Model {
var id: Node?
var name: Name
This generates a couple of "Type of expression is ambiguous without more context". I guess it relates to Node retrieving a string from the mySQL database and not knowing how to cast it into the Name type?