【问题标题】:Rswag nested attributes syntaxRswag 嵌套属性语法
【发布时间】:2020-08-25 18:52:09
【问题描述】:

我有一个项目,我必须在 rswag 中编写嵌套属性

{
  "question_bank": {
    "question_exams_attributes": {
      "0": {
        "question_bank_id": "",
        "exam_id": "12",
        "sub_category_id": "23",
        "_destroy": "false"
      }
    },
    "question_type": "Single best answer",
    "difficulty": "easy",
    "status": "active",
    "tag_list": [
      ""
    ],
    "question": "testing api 2"
  },
  "commit": "Submit"
}

我正在尝试在 rswag 中以嵌套属性语法编写此 json 正文: 我试过这个:

 parameter name: :question_bank, in: :body, schema: {
        type: :object,
        properties: {
          question_exams_attributes: {
            type: :object,
            properties: {
              '0': {
              properties: {
                question_bank_id: { type: :string },
                exam_id: { type: :string },
                sub_category_id: { type: :string }
                }
              }
            }    
          }    
        }

  }

【问题讨论】:

    标签: ruby-on-rails ruby rspec swagger rswag


    【解决方案1】:

    我也遇到过类似的问题。

    这是我解决它的方法。

    schema type: :object,
                properties: {
                  title: { type: :string },
                  content: { type: :string },
                  comments: {
                    type: :array,
                    items: {
                      type: :object,
                      properties: {
                        content: { type: :string }
                      }
                    }
                  }
                }
    

    在您的情况下,我认为您缺少“0”元素上的类型。

    properties: {
              question_exams_attributes: {
                type: :object,
                properties: {
                  '0': {
                  type: :object,
                  properties: {
                    question_bank_id: { type: :string },
                    exam_id: { type: :string },
                    sub_category_id: { type: :string }
                    }
                  }
                }    
              }    
            }
    

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多