Can't use "if-else" in very first position when defining validator with DSL
webblin034 opened this issue · 1 comments
webblin034 commented
Official Document :
" Accord supports several native Scala control structures, notably ifs and pattern matching "
in http://wix.github.io/accord/dsl.html
Library Dependencies :
libraryDependencies ++= Seq(
"com.wix" %% "accord-core" % "0.7.6" % Test,
"org.scalatest" %% "scalatest" % "3.2.2" % Test
)
Input Data :
case class InputData(
id: String,
name: Option[String] = None,
description: Option[String] = None,
items: Seq[String] = Seq.empty
)
Test Compilation OK :
implicit val inputDataValidator: Validator[InputData] = validator[InputData] { request =>
if (request.name.isDefined) {
} else {
request.name.mkString is notBlank
request.id is notBlank
request.description.mkString is notBlank
request.items is notEmpty
}
()
}
Test Compilation OK :
implicit val inputDataValidator: Validator[InputData] = validator[InputData] { request =>
request.name.mkString is notBlank
if (request.name.isDefined) {
} else {
request.id is notBlank
request.description.mkString is notBlank
request.items is notEmpty
}
()
}
Test Compilation Failed :
implicit val inputDataValidator: Validator[InputData] = validator[InputData] { request =>
if (request.name.isDefined) {
request.name.mkString is notBlank
} else {
request.id is notBlank
request.description.mkString is notBlank
request.items is notEmpty
}
()
}
Test Compilation Error :
[error] not found: value request
[error] if (request.name.isDefined) {
[error] ^
[error] one error found
noam-almog commented
this should solve things for you
r.name.each is notBlank
r.id is notBlank
r.description.each is notBlank
r.items is notEmpty
}