Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用swagger的Rails嵌套对象API_Ruby On Rails_Api_Swagger_Swagger Ui_Nested Resources - Fatal编程技术网

Ruby on rails 使用swagger的Rails嵌套对象API

Ruby on rails 使用swagger的Rails嵌套对象API,ruby-on-rails,api,swagger,swagger-ui,nested-resources,Ruby On Rails,Api,Swagger,Swagger Ui,Nested Resources,我使用swagger来描述rails应用程序中的API。我有两个rails模型。一个是作者,另一个是书籍。书籍和作者之间存在一对多的关系。一个作家可以有很多书。我想用一些书来创造一个新的作者。为此我写了这段代码 swagger_api :create do summary "Create new author" notes 'Create new Author with multiple books.' param :form, :name, :string, :required,

我使用swagger来描述rails应用程序中的API。我有两个rails模型。一个是作者,另一个是书籍。书籍和作者之间存在一对多的关系。一个作家可以有很多书。我想用一些书来创造一个新的作者。为此我写了这段代码

swagger_api :create do
  summary "Create new author"
  notes 'Create new Author with multiple books.'
  param :form, :name, :string, :required, "Author name"
  #Here books will come
  # Then some responses 
end

我如何定义这些书。因此,我可以使用swagger UI添加多本书

如果您的作者类中有:

有很多:书
接受书籍的\u嵌套\u属性\u

然后,您可以执行以下操作:


param:form,'author[book_attributes][title],:string,:optional

如果您的author类中有:

有很多:书
接受书籍的\u嵌套\u属性\u

然后,您可以执行以下操作:

param:form,'author[book_attributes][title],:string,:optional

尝试使用:

param :form, 'author[book_attributes][][title]', :string, :optional
尝试使用:

param :form, 'author[book_attributes][][title]', :string, :optional

只有当我将
book\u属性
更改为
book\u属性
时,上面的回答才开始对我起作用。但无论如何,非常感谢,伙计们

只有当我将
book\u属性
更改为
book\u属性
时,上面的回答才开始对我起作用。但无论如何,非常感谢,伙计们

如果您的对象数量为多个是动态的,该怎么办?有时它有一条记录,有时2..n如果您的对象数量为多个是动态的,该怎么办?有时它有一条记录,有时2,然后,您可以通过标准rails方式保存它,如果您使用它,那么swagger生成文档的形式会发送以下参数:{author:{book_attributes:[{title:'Test'}]},然后您可以通过标准rails方式保存它