Skip to content

How to allow empty array for params? #1370

Closed
@qsona

Description

@qsona

I wrote the following code.

params do
  requires :items, type: Array[JSON] do
    requires :id, type: Integer
    requires :enabled, type: Boolean
  end
end
post '/' do
# ...

A request with following params succeeds
{ items: [{ id: 1, enabled: true }, { id: 2, enabled: false }] }

But fails with following.
{ items: [] }

I changed the code to

params do
  optional :items, type: Array[JSON] do

But, all requests failed then.

I want to allow { items: [] } params. Is there any way to do it?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions