Decoding of values is done before validation. So when using enums and a Json library like Circe, if a value in an HTTP request is not of of the values in the enum, a decoding error is generated by Circe.
This error is also “leaked” to the response body, e.g. for validation
@validate(Validator.derivedEnumeration[Currency])
currency: Currency
The following response error is presented:
Invalid value for: body ('USD' is not a member of enum x.y.z.Currency$@6515ebbe at '[0].currency'
While expected would be something like:
Invalid value for: body ('USD' is not a member of enum Currency')
Using .mapValidate
validation can be done before decoding. However I could not get this to work with the validation annotation @validate
.
Any idea how to deal with this?