Closed robertjpayne closed 11 years ago
Agreed On May 11, 2013 1:26 AM, "Robert Payne" notifications@github.com wrote:
Take the below input JSON example:
{ 'text': 'This is an awesome text post!', 'attachment': null }
{ 'text': 'This is an awesome image post!', 'attachment': { 'type': 'image', 'url': 'myawesomeimage.jpg', } }
I'd love for my API to be able to validate against it but allow "attachment" to be completely optional. If attachment is non-nil though I'd want to ensure that type and url are both valid strings and part of the API spec.
Something like this could be really handle allowing it to be null and if so skip over the nested validators.
service.params.namespace :attachment, :null => true do |attachment| attachment.string :type, :required => true attachment.string :url, :required => true end
— Reply to this email directly or view it on GitHubhttps://github.com/mattetti/Weasel-Diesel/issues/23 .
I vote for this :+1:
I also have the use case for accepting an array of name-spaced objects that would be nice to have a min required if present or completely optional
{
"name" : "My Name",
"inner-objects" : [ {}, {}, {}]
}
{
"name" : "My Name"
}
Patch welcome ;) I think we all agree this feature needs to get in, nobody had time to write it yet tho.
On Thu, Jun 20, 2013 at 3:15 AM, Peter Heino notifications@github.comwrote:
I vote for this [image: :+1:]
I also have the use case for accepting an array of name-spaced objects that would be nice to have a min required if present or completely optional
{ "name" : "My Name", "inner-objects" : [ {}, {}, {}]} { "name" : "My Name"}
— Reply to this email directly or view it on GitHubhttps://github.com/mattetti/Weasel-Diesel/issues/23#issuecomment-19734521 .
With @kamui PR in, this should solve both @pheino and @robertjpayne problems. I'll close this issue for now, feel free to comment if you think that the provided solution isn't good enough,
Take the below input JSON example:
I'd love for my API to be able to validate against it but allow "attachment" to be completely optional. If attachment is non-nil though I'd want to ensure that type and url are both valid strings and part of the API spec.
Something like this could be really handle allowing it to be null and if so skip over the nested validators.