如何在Swagger-PHP中指定默认的JSON body?
How to specify the default JSON body in Swagger-PHP?
我想在 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 忽略此值并将 'string' 作为默认值:
如何将 'string' 部分更改为默认的 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(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"
* }
* )
*/
谢谢,
您可以通过修改您的 @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")),
* )
我想在 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 忽略此值并将 'string' 作为默认值:
如何将 'string' 部分更改为默认的 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(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"
* }
* )
*/
谢谢,
您可以通过修改您的 @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")),
* )