0

我想在 Swagger-PHP 中为 POST 请求指定默认的 JSON 正文。我的注释如下所示:

/**
 * Setup order
 *
 * @SWG\Post(
 *      path="/order/setup",
 *      operationId="setupOrder",
 *      tags={"Orders"},
 *      summary="Setup an order with status draft.",
 *      description="Setup an order with status draft",
 *      consumes={"application/json"},
 *      @SWG\Parameter(
 *          name="body",
 *          in="body",
 *          default="{}",
 *          description="Json order info body (customer and products info)",
 *          required=true,
 *          @SWG\Schema(type="string")
 *      ),
 *      @SWG\Response(
 *          response=200,
 *          description="successful operation"
 *       ),
 *       @SWG\Response(response=400, description="Bad request"),
 *       security={
 *           {"api_key_security_example": {}}
 *       }
 *     )
 *
 */

如您所见,我正在尝试使用default="{}",但 Swagger UI 忽略此值并将“字符串”作为默认值来实现默认值:

在此处输入图像描述

如何将“字符串”部分更改为默认 JSON 对象?

4

2 回答 2

5

您可以通过修改@SWG\Parameter().

示例(查看属性示例):

 *   @SWG\Parameter(
 *     name="body",
 *     in="body",
 *     description="User email used to create account.",
 *     required=true,
 *     @SWG\Schema(@SWG\Property(property="email", type="string", example="email@example.com")),
 *   )

此注释将生成类似这样的内容

于 2018-07-11T08:46:35.953 回答
0

你可以像下面这样使用。

/**
 * Setup order
 * @SWG\Post(
 *      path="/order/setup",
 *      operationId="setupOrder",
 *      tags={"Orders"},
 *      summary="Setup an order with status draft.",
 *      description="Setup an order with status draft",
 *      consumes={"application/json"},
 *      @SWG\Parameter(
 *          name="body",
 *          in="body",
 *          default="{}",
 *          description="Json order info body (customer and products info)",
 *          required=true,
 *          @SWG\Schema(ref="#/definitions/testDefinitions")
 *      ),
 *      @SWG\Response(
 *          response=200,
 *          description="successful operation"
 *       ),
 *       @SWG\Response(response=400, description="Bad request"),
 *       security={
 *           {"api_key_security_example": {}}
 *       }
 *     )
 *  @SWG\Definition(
 *      definition="PlanResponse",
 *      example={
 *         "type":"string"
 *      }
 *     )
 */

谢谢,

于 2018-04-21T13:30:40.277 回答