【问题标题】:Grape route with array as root object以数组为根对象的葡萄路线
【发布时间】:2016-06-26 21:40:52
【问题描述】:

我正在为这样的葡萄路线定义参数

    params do
      requires :array, type: Array do
          requires :foo, type: String
          requires :bar, type: String
      end
    end

此端点的数据为{"array": [{"foo": "123", "bar": "456"}]}

我怎样才能摆脱额外的"array"?数据应如下所示[{"foo": "123", "bar": "456"}]

我无法在 params 上定义类型 Array

【问题讨论】:

标签: ruby grape grape-api


【解决方案1】:

您可以使用群组来执行此操作,更多信息请访问 https://github.com/ruby-grape/grape#group-options

例如: 参数做 组:数组,类型:数组做 需要:foo,类型:字符串 需要:bar,类型:字符串 ... 结尾 结束

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多