【问题标题】:Swagger Documentation - How can i get only values separated by a comma in the json request body?Swagger 文档 - 如何在 json 请求正文中仅获取由逗号分隔的值?
【发布时间】:2020-08-15 17:25:55
【问题描述】:

在我的例子中,对于 DELETE 操作,我必须传递一个如下所示的主体。

请求正文应如下所示:

[
 "Vi####1",
 "Vi####2"
]

但是当我试图实现这一点时,我总是得到数据类型以及如下所示的值。

当前正在创建的请求正文:

{
 "Vi####1": "string",
 "Vi####2": "string"
}

请在下面找到 json 创建。

class VirtualViewColDeleteReq
{

/**
 * @OA\Property(
 *     title="View ID",
 *     description="Segment Name",
 *     property="Vi####001"
 * )
 *
 * @var string
 */

/**
 * @OA\Property(
 *     title="View ID1",
 *     description="Segment Name",
 *     property="Vi####002"
 * )
 *
 * @var string
 */

}

swagger.php

 *     @OA\RequestBody(
 *          required=true,
 *          @OA\JsonContent(ref="#/components/schemas/VirtualViewColDeleteReq")
 *      ),

非常感谢任何帮助。

提前致谢

【问题讨论】:

    标签: annotations swagger swagger-php


    【解决方案1】:

    您当前的设置描述了一个对象,但看起来您想要一个带有字符串的简单数组

     *     @OA\RequestBody(
     *       required=true,
     *       @OA\JsonContent(
     *         type="array", 
     *         @OA\Items(type="string"),
     *       )
     *     )
    

    为了更清楚起见,您可以提供格式 @OA\Items(type="string", format="id"), 这会被工具忽略,但会向文档的读者提供提示。

    【讨论】:

    • 嘿鲍勃,它帮助了我。感谢您的解决方案:)
    猜你喜欢
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多