Как указать тело JSON по умолчанию в Swagger-PHP?

Я хочу указать тело JSON по умолчанию для запроса POST в Swagger-PHP. Мои аннотации выглядят так:

/**
 * 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 игнорирует это значение и вместо этого помещает «строку» в качестве значения по умолчанию:

введите здесь описание изображения

Как изменить часть «строка» на объект JSON по умолчанию?


person Paul    schedule 19.04.2018    source источник


Ответы (2)


Вы можете добиться того, чего ожидали, изменив файл @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 protected]")),
 *   )

Эта аннотация создаст что-то вроде этого

person Pusparaj    schedule 11.07.2018

Вы можете использовать, как показано ниже.

/**
 * 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"
 *      }
 *     )
 */

Спасибо,

person Pratik Mehta    schedule 21.04.2018