【问题标题】:Rswag nested objects, rswag syntaxrswag 嵌套对象,rswag 语法
【发布时间】:2018-11-25 00:20:02
【问题描述】:

我有一个项目,其中有嵌套对象。我试图找出嵌套数组的正确语法。这是我已经厌倦的事情(在许多其他事情中):

parameter name: :measurement, in: :body, schema: {
  type: :object,
  properties: {
    measurement_code: { type: :string },
  },
  type: :array_of_objects,
  measure: { type: :array },
  items: {
    value: { type: :integer }
    name: { type: :string }
    id: { type: :integer }
  },
  required: []
}

我发送的示例数据:

{"measurement_code"=>"918031199-7",
 :measure=>
  [
    {
    "id": 1,
    "value": 8049,
    "name": "Temporibus quam et ipsum blanditiis hic."
    },
    {
    "id": 2,
    "value": 76060,
    "name": "Sint omnis."
    }]
  }
}

【问题讨论】:

  • 您能否给出您在使用此语法时遇到的确切问题 - 错误消息、警告等?
  • 我认为我离正确的语法太远了。 rswag 中的文档很少,实际的 swagger 语法似乎有所不同。
  • 感谢@waldrumpus 派我去调试和谷歌一轮:D。这解决了我的问题:stackoverflow.com/questions/26206685/…。添加到原始问题的正确解决方案。
  • 很好,干得好!您可以自己发布一个包含您的发现的答案,如果您愿意,可以将其作为正确的接受,或者如果该问题与您找到解决方案的答案过于接近,则可以投票关闭此问题作为重复问题。
  • 是的,感谢@waldrumpus 的提议。堆栈溢出新手在这里。第一个问题..

标签: ruby-on-rails ruby-on-rails-5 rspec-rails


【解决方案1】:

这用作对象数组的 rswag 语法:

  properties: {
    measurement_code: { type: :string },
    measure: {
      type: :array,
      items: {
        properties: {
          value: { type: :integer },
          name: { type: :string },
          id: { type: :integer }
        }
      },
    },
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2021-06-05
    相关资源
    最近更新 更多