Javascript 如何在Swagger中定义FormData中对象的动态数组?

Javascript 如何在Swagger中定义FormData中对象的动态数组?,javascript,php,swagger,swagger-ui,Javascript,Php,Swagger,Swagger Ui,例如,如果您想要一个端点: POST/products 可以接受多个“产品”添加到目录或其他内容,您可以创建如下所示的HTML表单: <form method="post" action="/products"> <input type="text" name="name[]" /> <input type="text" name="price[]" /> <input type="text" name="name[]" /&

例如,如果您想要一个端点:

POST/products

可以接受多个“产品”添加到目录或其他内容,您可以创建如下所示的HTML表单:

<form method="post" action="/products">

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

</form>
 *@SWG\Post(
 *     tags={"Products"},
 *     path="/products",
 *     operationId="addProducts",
 *     consumes={"application/json"},
 *     produces={"application/json"},
 *     @SWG\Response(
 *          response=201,
 *          description="The newly created Products as JSON"
 *     ),
 *     @SWG\Parameter(
 *          description="Name of the Product",
 *          name="name",
 *          type="string",
 *          in="formData",
 *          required=true
 *     ),
 *     @SWG\Parameter(
 *          description="Price of the Product",
 *          name="price",
 *          type="number",
 *          format="int32",
 *          in="formData",
 *          required=true
 *     )
 * )
这很容易,但让我的招摇过市的文档来代表这一点是很难的;更具体地说,让Swagger UI html页面向用户显示每个名称-价格对代表集合中的一个项目。应向用户显示一个
+
按钮,向集合中添加另一个“项目”,然后同时提交所有“产品”

招摇过市的定义中有什么东西可以代表这一点吗?我知道我可以创建一个
array
类型,它会起作用,但这会使API用户的发现和测试变得更加困难。我还希望避免使用JSON有效负载,并坚持使用FormData

我还使用了Swagger PHP DocBlock表示。在这种情况下,我会这样做:

<form method="post" action="/products">

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

    <input type="text" name="name[]" />
    <input type="text" name="price[]" />

</form>
 *@SWG\Post(
 *     tags={"Products"},
 *     path="/products",
 *     operationId="addProducts",
 *     consumes={"application/json"},
 *     produces={"application/json"},
 *     @SWG\Response(
 *          response=201,
 *          description="The newly created Products as JSON"
 *     ),
 *     @SWG\Parameter(
 *          description="Name of the Product",
 *          name="name",
 *          type="string",
 *          in="formData",
 *          required=true
 *     ),
 *     @SWG\Parameter(
 *          description="Price of the Product",
 *          name="price",
 *          type="number",
 *          format="int32",
 *          in="formData",
 *          required=true
 *     )
 * )
如您所见,我可以指定
参数
,但我只需要一些额外的胶水来告诉Swagger,这两个参数表示动态大小数组中的单个项


有什么想法吗?

HTML表单POST请求是
application/x-www-form-urlencoded
multipart/form data
,而不是
application/json
。您需要使用表单数据还是JSON?OpenAPI/Swagger 2.0支持JSON中的动态数组,但不支持表单数据。“消耗”部分是不正确的。所以看起来我必须改为使用JSON负载?如果那是唯一的选择那就好了。你知道我是否可以让swagger UI以我提到的“添加新项目”的方式来表示这一点吗?是的,在swagger UI v中。2.2.10使用
jsonEditor:true
(但不在3.0.x中)。