Open lenzenc opened 9 years ago
I'm not sure what you need. ActiveRecord-ish DSL? If so, we need to build new APIs that make full use of Java reflection API calls and implicit conversions... I'm not sure that's really nice.
Currently, skinny-validator can work with case classes. I hope you'll like it.
http://skinny-framework.org/documentation/validator.html
scala> import skinny.validator._
import skinny.validator._
scala> case class Person(name: String)
defined class Person
scala> val person = new Person("Alice")
person: Person = Person(Alice)
scala> val validator = Validator(param("name" -> person.name) is required)
validator: skinny.validator.Validator = skinny.validator.Validator@57f1ccde
scala> validator.errors
res1: skinny.validator.Errors = Errors(Map())
scala> val validator = Validator(param("name" -> person.name) is required & maxLength(3))
validator: skinny.validator.Validator = skinny.validator.Validator@a725f13
scala> validator.errors
res2: skinny.validator.Errors = Errors(Map(name -> List(Error(name = maxLength, messageParams = List(3)))))
If you hope to simplify param("name" -> person.name) is required
more, I can understand. But, just an idea, enabling person.name is required
will require quite heavy implicit conversions there. I'm afraid it won't make developers happy due to its negative side effect.
Are there any examples or extensions available to use case classes with the validation framework?
I guess it would be easy enough to just write a bit of code to turn a case class to a map and use the MapValidator, but it would be nice to have a similar validation feel like in RoR. Something like...
Thoughts?