# Use @validate before decoding phase

**URL:** <https://softwaremill.community/t/use-validate-before-decoding-phase/51>\
**Category:** tapir\
**Created:** [December 28, 2022, 10:32am UTC](https://softwaremill.community/t/use-validate-before-decoding-phase/51 "2022-12-28T10:32:33Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![frevib](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/frevib/32/48_2.png) [@frevib](https://softwaremill.community/u/frevib)\
**Post date:** [December 29, 2022, 12:23pm UTC](https://softwaremill.community/t/use-validate-before-decoding-phase/51/3 "2022-12-29T12:23:30Z")

</div>

Thanks for the quick reply @adamw!

This approach would solve the problem, indeed. However, it would be more elegant if `@validate` could be used to also validate the enum.

What happens now is that with all of the validations used in for instance:

```auto
  @validate(Validator.derivedEnumeration[Currency])
  currency: Currency
  @validate(Validator.min(0))
  age: Int
  @validate(Validator.pattern("[0-9]+"))
  someNumber: String,

```

we get a nice aggregation of the incorrect values:

```auto
expected age to be greater than or equal to 0, but got -1,
expected someNumber to match: [0-9]+, but got: \"ABCD\"

```

But the validation error for the enum will not be in that message. If I understand correctly, the decoding will done before validation, and will produce a separate error.

This also makes me wonder what the use of `Validator.derivedEnumeration[Currency]` is, apart from documentation. It will be executed after Circe’s decoding, which already proves that the value sent by the user is one of the values of the enum.

So ideally, something like this would be the error message:

```auto
expected currency to be one of ["EUR", "USD"], but got "NZL",
expected age to be greater than or equal to 0, but got -1,
expected someNumber to match: [0-9]+, but got: \"ABCD\"

```

---

_[View the full topic](https://softwaremill.community/t/use-validate-before-decoding-phase/51)._
