Skip to content

'optional' Array with nested 'requires' params  #723

Closed
@ipkes

Description

@ipkes

Grape v 0.8.0

Headers:
Content-Type: application/json
Accept: /
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,ru;q=0.6

Validation:

params do
  requires :docs do
    requires :type, type: String
    optional :files do 
      requires :href, type: String
    end
  end
end

Package json(with xml same problem):

{
  "docs": [
       {"type": "aaa"}, 
       {"type": "bbb", "files": [{"href": "some_href"}] }
  ]
}

Result:

<error>
  <message>docs[files][href] is missing</message>
</error>

This

{
  "docs": [
      {"type": "aaa"}
  ]
}

and this:

{
  "docs": [
     {"type": "bbb", "files": [{"href": "som_href"}] }
  ]
}

Works fine!
Help plz! What I'm doing wrong? Sorry if subject duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions