-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feature: Support validations on array items #50
Feature: Support validations on array items #50
Conversation
I've sat down again and noticed that allowing the usage of Maybe |
Thanks for your PR. I'll review your code in the coming days. In general, good edge cases to test for are:
|
Another interesting test case is the array length. For example, a test where 2 items are passed but it is limited to |
The current implementation will return both the array error and and errors to the items. This is because we don't stop validating once we find an error: list: [
"item should be at least 3 character(s)",
"should have at most 1 item(s)"
] I feel it makes sense to keep this behavior for two reasons:
That said, I'm open to change this if you feel strongly about it :) While writing new test cases, my implementation also has a bug first mentioned in #44. Since that isn't merged yet, I have gone ahead and fixed both instances I could find and added some specific tests to verify this behavior. |
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 very good! 👏🏻 I left some suggestions and a question
@martinthenth I have implemented most of your suggestions and have commented on the ones I'd challenge. Have a look :) |
I'm having a hard time figuring out why these tests fail on CI. I've tested an erlang/elixir version as close to what the CI job runs (elixir 1.13.4-opt-24 with erlang 24.3.4.11) as I can install on my computer. The tests all succeed. @martinthenth can you run them locally? |
I tried them locally and they pass 🤔 So I tried updating from the most recent master branch, and it looks your branch was on an older Maybe it has to do with |
@martinthenth You are correct, the changes to what As far as I understand, the old logic was that With version 3.10.0, they changed this behavior and I have adopted the tests to the new behavior. I have also rebased my fork branch onto your main, so that it merges again and has clean history. |
* Reduced nesting to linted levels * Moved error mapping to function tail * Extended on comment about error/changes strategy
The validation functions from Ecto work for lists out of the box, so no new code needed to be written here.
…ity. This duplicates #44 partially, but I have made the test-case more specific.
I recall there was an issue with required fields with empty values. 🤔 The default settings of Ecto exclude empty fields from the changeset, which is problematic when a field is intended to be changed to In general, if the client sends the parameters and the backend expects those fields then empty values should not be invalidated unless they are explicitly invalid (from the rules)
Great! I will take a look at the updated code soon 🙂 |
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 work! 💯 I can prepare a release that includes these changes soon 🙏🏻
This is my first stab at implementing #49
To this end, I have implemented a new
validate_array_basic_field/5
function, which is called byvalidate_nested_fields/3
for any supported basic type.It works much like the existing
validate_array_field/4
function (which has been renamed), but it does some mangling of the changesets in order to have all errors be listed for the{:array, type}
field.Please also see the tests for the expected usage/output of this.
Questions/Ideas
items:
reads better in the DSL?ToDo