0

我有一个项目,我必须在 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 }
                }
              }
            }    
          }    
        }

  }
4

1 回答 1

0

我也遇到了类似的问题。

这是我解决它的方法。

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 }
                }
              }
            }    
          }    
        }
于 2020-12-24T14:03:17.400 回答