Hi I've a question about input validation.
An endpoint accepts a payload described by some data classes.
I've added a validation in a data class, like this:
data class Payment(
val type: PaymentType,
val amount: Float,
val reason: String,
val expiryDate: String,
val code: String,
val lisHoldingCode: String
) {
init {
require(reason.isNotEmpty()) { "Payment reason cannot be empty" }
require(code.isNotEmpty()) { "Payment code cannot be empty" }
require(lisHoldingCode.isNotEmpty()) { "Lis code cannot be empty" }
}
Now I am writing a test to assure that validation rules are respected (ie invalid payload are not accepted).
This happens but message is too vague:
{"message":"Missing/invalid parameters","params":[{"name":"body","type":"body","datatype":"object","required":true,"reason":"Invalid"}]}
I would need a message which clearly states
which parameter is wrong, using the message I've putted in the require
How can I do that?
Thanks in advance