-
Notifications
You must be signed in to change notification settings - Fork 399
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
support Validator preservation #3408
Comments
I'm not sure what you're trying to achieve, but I think there are two ways. In your code above you explicitly use Option 1 is to use the macro-based derivation: case class LongString(@validate(Validator.minLength(3)) v: String)
case class OptionWrapper[A](opt: Option[A])
val s = implicitly[Schema[OptionWrapper[LongString]]]
println(s.applyValidation(OptionWrapper(Some(LongString("aaa")))))
println(s.applyValidation(OptionWrapper(Some(LongString("aa")))))
println(s.applyValidation(OptionWrapper(None))) this prints (as expected)
Option 2 is more manual, and involves mirroring what implicit Option schema derivation does - constructing an val longStringSchema = Schema.schemaForString.validate(Validator.minLength(3))
val longStringWrappedSchema: Schema[OptionWrapper[String]] = Schema(
schemaType = SOption(longStringSchema)(_.opt),
isOptional = true,
format = longStringSchema.format
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tapir version: 1.9.5
Scala version: 2.13.12
Describe the bug
Can't find a way to keep the validator in case of an optional field
How to reproduce?
https://scastie.scala-lang.org/GVBxeZypSA6DiBcUa1dFGw
Additional information
it will be great if
validator.contramap
supported option transformation:The text was updated successfully, but these errors were encountered: