Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input validation #7

Closed
takezoe opened this issue Nov 28, 2016 · 0 comments
Closed

Input validation #7

takezoe opened this issue Nov 28, 2016 · 0 comments

Comments

@takezoe
Copy link
Owner

takezoe commented Nov 28, 2016

I have some ideas to introduce validation capability to Resty.

assert properties in the constructor

The simplest idea is assert in the constructor of the case class:

case class Message(message: String){
  assert(message.nonEmpty, "message is empty.")
}

Response would be:

{
  "errors": [
    "assertion failed: message is empty."
  ]
}

validate method of the case class

Second idea is implementing validation logic as validation() method of the case class:

case class Message(message: String) extends ValidationSupport {
 override def validate(): Option[ErrorModel] = {
   if(message.isEmpty){
     Some(ErrorModel(Seq(message is empty.)))
   } else {
     None
   }
 }
}

annotation for the case class

Third idea is providing validation annotations for the case class:

case class Message(
  @NonEmpty @MaxLength(100) message: String
)

BeanValidation might be another choise instead of original annotations.

takezoe added a commit that referenced this issue Dec 23, 2016
(refs #7)Validation support for input parameters
@takezoe takezoe closed this as completed Dec 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant