-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): add custom validation framework #1756
feat(api): add custom validation framework #1756
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1756 +/- ##
==========================================
+ Coverage 67.38% 67.72% +0.33%
==========================================
Files 781 795 +14
Lines 16747 16981 +234
Branches 1056 1079 +23
==========================================
+ Hits 11285 11500 +215
- Misses 5004 5018 +14
- Partials 458 463 +5
Help us with your feedback. Take ten seconds to tell us how you rate us. |
ae3e7b8
to
62c4633
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really promising!
A test showing the a custom validation implemented would help the comprehension, I know that's still a draft, but it would be a nice to have in the final version of the PR
...tp/jersey/src/main/java/org/eclipse/dataspaceconnector/extension/jersey/JerseyExtension.java
Show resolved
Hide resolved
|
||
import java.lang.reflect.Method; | ||
|
||
public class ValidationFunctionRegistryImpl implements ValidationFunctionRegistry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an avoidable indirection layer, could ResourceInterceptorProvider
directly implement ValidationFunctionRegistry
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically we could do that, but the idea was to make the ResourceInterceptorProvider
a generic hook point that could be used for other things too, not only validation, so it is a generic layer, that doesn't need to know about validation, whereas the ValidationFunctionRegistry
"binds" it specifically to the validation use case.
Also, I liked the idea of having a clean user-facing interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, so I gave it a try, and I do actually like it. check the respective commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paullatzelsperger maybe the ValidationFunctionRegistry
could be called InterceptorFunctionRegistry
?
That would make it more generic looking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it before, wasn't sure, and considering that everything else is called "interceptor"-something and you also now mentioned it, I'm fine with it.
That's a cool idea - I'll add an integration test for that |
4b835e8
to
9e3dd38
Compare
9e3dd38
to
29289a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far.
Just one additional point: We should maybe also describe at least in the documentation, that the failure message is "important" to be a good one, as it will be returned to the client in the response body.
.../eclipse/dataspaceconnector/extension/jersey/validation/ResourceInterceptorProviderTest.java
Outdated
Show resolved
Hide resolved
...java/org/eclipse/dataspaceconnector/extension/jersey/validation/ResourceInterceptorTest.java
Outdated
Show resolved
Hide resolved
All failure messages should be treated as "good ones". No point in stating that explicitly. |
Co-authored-by: Florian Rusch (ZF Friedrichshafen AG) <florian.rusch.external@zf.com>
840c8ce
to
77972ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, LGTM 🚀
* feat(api): add custom validation framework * added documentation * updated docs * Apply suggestions from code review Co-authored-by: Florian Rusch (ZF Friedrichshafen AG) <florian.rusch.external@zf.com> * renamed to InterceptorFunctionRegistry Co-authored-by: Florian Rusch (ZF Friedrichshafen AG) <florian.rusch.external@zf.com>
What this PR changes/adds
This PR adds a convenient way for users to register their own validation functions for API methods.
Why it does that
Extensible validation may be desired by users, especially when dealing with extensible types.
Further notes
ValidationFunction
, which is a marker forFunction<Object[], Result<Void>>
. This was done to improve readability.Example Usage
Linked Issue(s)
Closes #1736
Checklist
no-changelog
)