-
Notifications
You must be signed in to change notification settings - Fork 1
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
Request with missing nested map param throws validation error when "type: :map" specified for param #23
Comments
hey thanks for raising this! sorry in advance for formatting as i am travelling for the next week and typing this via the app the order of the rules do matter, which i need to document better if you move the nullable rule before the it would be nice to add a "presence" rule though like you mentioned, so ill look into that when i'm back! |
Hi @ozziexsh, thanks for the reply while traveling. Impressive formatting while on the move 😄 I tried out your suggestion to move the nullable rule before the One suggestion on that (and no worries if it is too much work to implement - it's just a thought), if your library could hoist the nullable rule before the A "presence" rule sounds good 👍 I guess it would be an interesting area to document. I guess "required" means that a key and value are required (then setting "nullable" allows the value to be nil). Whereas "presence" would be that a key is required (this begs the question, how would presence" be meaningfully different from No rush replying. Enjoy the travels and I'm happy to take up this again when you get back or when you get a chance to look at this. Especially, now that you've explained the rule ordering, I'm unblocked. |
Thanks for you work on the project @ozziexsh !
I have found a issue when I am working with nested parameters. Here is my example...
The Problem
type: :map
specified for the "address" paramWorkaround
If I comment up the
type: :map
specified for the "address" param and repeat the experiment I get no validation errors (as expected). ie.Here is the example in a unit test...
This test fails. If you comment out the
type: map
line it passes.My Expectation
This issue occurred when I was used the plug / form request approach. In that scenario, when I stop submitting an "address" param with the HTTP request, the request param obviously does not get sent at all to the server (ie. I won't get a
%{"address" => nil}
, rather I will get%{}
and that is problematic. I am not sure if the "nullable" option is behaving as you would expect in the above scenario - maybe it is. If it is behaving as expected then maybe aallow_missing: true
option could be added? This would allow a param to be absent as well as present but nil - though that I what I would expect therequired: false
to allow me to do.P.S. I can workaround the issue by not supplying
type: :map
of course - but that seems like a hack - really what I should be able to specify here is a map that can be missing.The text was updated successfully, but these errors were encountered: