mattetti / Weasel-Diesel

DSL to describe, document and test web services
MIT License
438 stars 21 forks source link

Support for optional namespaces #23

Closed robertjpayne closed 11 years ago

robertjpayne commented 11 years ago

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
mattetti commented 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 .

pheino commented 11 years ago

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"
}
mattetti commented 11 years ago

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 .

mattetti commented 11 years ago

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,