Skip to content
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

Implement a Clamp modifier/validator #740

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

godexsoft
Copy link
Collaborator

This implements support for modifiers such as Clamp.
See ClampingValidator test for usage examples.

If we decide to go this path we probably will want to rename Validator and validate to something that implies possible modification to the original json value.

Most of the validators can continue receiving a const& of the json value. Only modifiers and containers for other validators/modifiers need to remove the const.

I'm certainly not a huge fan of this "design" but i don't see another way to achieve clamping if we need it.
Sometime in the future perhaps we could integrate the parsing steps into this framework instead of relying on user-provided value_from and value_to but for now this approach is least blood for modifiers support.

Let me know your thoughts @cindyyan317 and @ximinez.

@cindyyan317
Copy link
Collaborator

Thanks for quickly fixing this!
The mutation in validation looks okay for me. You change the name to "Clamp" which is clear enough. For some validation like account , the validation and parsing is the same operation, currently we do it on accounts twice. In future, with proper parsing step, we can even convert to the different type.

@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

❗ No coverage uploaded for pull request base (develop@271323b). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 3a6b9e0 differs from pull request most recent head d78d65a. Consider uploading reports for the commit d78d65a to get more accurate results

@@            Coverage Diff             @@
##             develop     #740   +/-   ##
==========================================
  Coverage           ?   34.59%           
==========================================
  Files              ?      161           
  Lines              ?     8207           
  Branches           ?     4809           
==========================================
  Hits               ?     2839           
  Misses             ?     2814           
  Partials           ?     2554           

Make only modifiers require mutability

[fold] Get const back in tests

[fold] Make tests compile

[fold] Fix const requirement

[fold] Refactor a bit

[fold] A couple more small renames
@godexsoft godexsoft force-pushed the feature/rpc-parsing-thru-spec branch from 800c714 to 3a6b9e0 Compare July 10, 2023 12:52
@godexsoft
Copy link
Collaborator Author

Handlers and other parts of clio can remain using const object as request now that the default processor makes a copy of the request and validation framework operates on the mutable copy instead.
Modifiers, validators and meta handlers were all refactored out to separate namespaces and files.

@godexsoft godexsoft marked this pull request as ready for review July 10, 2023 12:58
cindyyan317
cindyyan317 previously approved these changes Jul 10, 2023
Copy link
Collaborator

@cindyyan317 cindyyan317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@godexsoft godexsoft merged commit ba8e718 into XRPLF:develop Jul 10, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants