You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While Courier supports data validation, the validator functions it provides need to be called explicitly.
That's feasible when used with the right frameworks - such as Naptime - which call the validator functions at interface boundaries, but it is impractical for other use cases.
A user might prefer if invalid constructions such as new JeopardyResponse(question = "Why is the sky blue") failed early without any explicit call to validation.
Currently the closest they can get is by either
calling validation at every construction site, which is error prone and tedious
rolling their own wrapper types that call validation (more complicated than it sounds, e.g. generated Scala classes are final)
The bottom line is that users who want their models validated at construction time have to write code that could be generated.
Proposed Solution
Adding a new annotation would let users label types which need to be validated at construction time:
Courier would then generate constructor code that calls the validator function and signals failure in an idiomatic way. For example, in Java and Scala, new JeopardyResponse(question = "Why is the sky blue") would throw an IllegalArgumentException.
The text was updated successfully, but these errors were encountered:
The Problem
While Courier supports data validation, the validator functions it provides need to be called explicitly.
That's feasible when used with the right frameworks - such as Naptime - which call the validator functions at interface boundaries, but it is impractical for other use cases.
For example, consider the following model:
A user might prefer if invalid constructions such as
new JeopardyResponse(question = "Why is the sky blue")
failed early without any explicit call to validation.Currently the closest they can get is by either
final
)The bottom line is that users who want their models validated at construction time have to write code that could be generated.
Proposed Solution
Adding a new annotation would let users label types which need to be validated at construction time:
Courier would then generate constructor code that calls the validator function and signals failure in an idiomatic way. For example, in Java and Scala,
new JeopardyResponse(question = "Why is the sky blue")
would throw anIllegalArgumentException
.The text was updated successfully, but these errors were encountered: