如何修复消息中的 "Ignored duplicated keys"

How to fix "Ignored duplicated keys" in message

我正在使用 Savon 测试某些 WSDL SOAP 服务,并且某些服务需要在消息中重复 keys/values。例如 "products" 数组中的 "product" 值:

@client.call(
  :create_template, message: {
    :item => [{
      'promotion_id'      => "1",
      'code_is_unique'    => "0",
      'name'          => "qasusc1",
      'description'     => "Automation suscription",
      'basecode'        => "qasusc1",
      'total_redemptions'   => "30",
      'valid_from'      => "2016-12-12 00:00:00",
      'valid_to'        => "2017-12-12 00:00:00",
      'duration_quantity'   => "1",
      'duration_unit'     => "M",
      'operator_code'     => "NAME",
      'initial_quantity'    => "30",
      :products => [{
        :product => [{
          'id'          => "3",
          'off_percentage'    => "100",
          'quantity'        => "1"
        }],
        :product => [{
          'id'          => "4",
          'off_percentage'    => "100",
          'quantity'        => "1"
        }]
      }],
      :lists => [{
        'list'          => "1"
      }],
      :promotion_rules => [{
        :promotion_rule => [{
          'code'    => "HAS_PAYMENT_GATEWAY_RULE",
          'value'   => "1"
        }]
      }]
    }]
  }
)

但我收到以下错误:

tests/suites_soap/test_soap.rb:840: warning: duplicated key at line 22 ignored: :product

您不能在哈希内复制键,句点。

{ a: 1, a: 2 } 总是 等于 {a: 2}.

根据this issue,您应该使用数组来表示 Ruby 形式的重复键:

:products => [{
  :product => [
    {
      'id'                    => "3",
      'off_percentage'        => "100",
      'quantity'              => "1"
    },
    {
      'id'                    => "4",
      'off_percentage'        => "100",
      'quantity'              => "1"
    }
  ]