| 1 | # Validation engine |
| 2 | |
| 3 | ## Decision |
| 4 | |
| 5 | We're removing Jakarta Validation engine and replace it with a self-implemented one. |
| 6 | |
| 7 | ## Rationale |
| 8 | |
| 9 | With the support of JsonLD semantics, the Jakarta Validation framework became useless, because it relies on "Java Beans", |
| 10 | that we described with `Dto` classes, while we need a validation that needs to be applied after JsonLD expansion, so |
| 11 | it need to validate expanded `JsonObject` objects. |
| 12 | |
| 13 | ## Approach |
| 14 | |
| 15 | We will follow a validator pattern, where a validator is an implementation of an interface like: |
| 16 | ``` |
| 17 | interface Validator<T> { |
| 18 | ValidationResult validate(T input); |
| 19 | } |
| 20 | ``` |
| 21 | |
| 22 | This way every `Controller` will need to have a `Validator` instance injected that will be applied on the expanded |
| 23 | `JsonObject` and, if the validation fails, a `ValidationFailureException` will be thrown and then caught by a dedicated `ExceptionMapper` |
| 24 | that will return a 400 response with a detailed response body. |
| 25 | |
| 26 | The `ValidationResult` should contain a list of `Violation`s, and every one of those should bring details about what's wrong |
| 27 | with the request and what's expected from the api. |