我有一个项目,其中我必须在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 }
}
}
}
}
}
}发布于 2020-12-24 22:03:17
我也遇到过类似的问题。
下面是我解决这个问题的方法。
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 }
}
}
}
}
}https://stackoverflow.com/questions/63585364
复制相似问题