Elffuss BraidHub

kikocis/EDC public

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