首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rswag嵌套属性语法

Rswag嵌套属性语法
EN

Stack Overflow用户
提问于 2020-08-26 02:52:09
回答 1查看 207关注 0票数 0

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

代码语言:javascript
复制
{
  "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主体:我已经尝试过了:

代码语言:javascript
复制
 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 }
                }
              }
            }    
          }    
        }

  }
EN

回答 1

Stack Overflow用户

发布于 2020-12-24 22:03:17

我也遇到过类似的问题。

下面是我解决这个问题的方法。

代码语言:javascript
复制
schema type: :object,
            properties: {
              title: { type: :string },
              content: { type: :string },
              comments: {
                type: :array,
                items: {
                  type: :object,
                  properties: {
                    content: { type: :string }
                  }
                }
              }
            }

在你的例子中,我认为你错过了"0“元素的类型。

代码语言:javascript
复制
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 }
                }
              }
            }    
          }    
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63585364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档