-
Notifications
You must be signed in to change notification settings - Fork 184
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
Dry-validation: Unsupported error format in case (input predicate) #403
Comments
This would need to be handled in Representable first as if you try it will attempt to deserialize your input params before running validation and will trigger an error as Representable expects a hash. Can you remind me why you want to be able to pass anything other than a hash to validate? |
It's not me who wants to pass anything else, it's dry-validation ;). Apparently in most cases it returns a Hash, but in some cases (like when using the 'input' keywords) it returns an array Just tested it again with dry-validation version 0.10.3 :
Typical example could be validating a REST API parameter set. I want to be sure a Hash is received and not an Array to prevent my code to blow up (which actually happens when using Grape) |
Could you show your form that triggers this behaviour? I don't understand how that can happen?!?! |
@apotonick I stopped working on this because reform requires inputs to be a hash. End of so you won't ever be able to use this type of rule via Reform. The only way to support this would be |
@apotonick I don't think a form will trigger this (except if someone is manually constructing form posts of course). However when using reform with a public REST API IMHO it seems better to always validate input data as much as possible, i.e. validate data at the start so it can be trusted to be in the correct format for future use in the code. |
This ticket was created when using the 'improve-dry-integration' branch created by @fran-worley
2 different error outputs formats are available when using dry-validation (tested with dry-validation 0.10.3)
Hash using the related field name as key
Dry::Validation.Schema {required(:bla).filled}.call({:ff => 'jkhjk'}).messages
=> {:bla=>["is missing"]}
Array listing global errors
Dry::Validation.Schema {input(:hash?)}.call([]).messages
=> ["must be a hash"]
Currently only the Hash format is supported:
Quick fix could be to re-introduce the 'base' keyword similar to AR, for example http://pastebin.com/X9vWAXjC. Perhaps a better solution is available?
The text was updated successfully, but these errors were encountered: