Swagger PHP - 如何定义嵌套属性?

时间:2016-05-20 09:05:20

标签: php swagger-php

我正在使用Swagger PHP,并且大多数定义都很容易定义,但我遇到的问题是某个特定的数据不属于单独的类,而是一个关联数组。

我希望展示的json响应(针对此问题进行了简化):

$interval

{ "id": 1, "status": "published", "gps": { "lat": "0.00000000", "lng": "0.00000000" } id很容易定义,但是status是一个问题,因为没有单独的类来定义它,它是模型中的数组。是否可以定义此数组而无需创建虚拟类?

目前模型文件中的注释:

gps

1 个答案:

答案 0 :(得分:12)

面对完全相同的问题,今天就解决了!

  

这是针对 Swagger 2.0

以下是我用来实现嵌套参数的注释嵌套..

/**
 * @SWG\Post(
 *   path="/getCustomerByEmail.php",
 *   summary="List the details of customer by the email.",
 *   consumes={"string"},
 *   produces={"application/json"},
 *   @SWG\Parameter(
 *     name="email",
 *     in="body",
 *     description="Customer email to ge the data",
 *     required=true,
 *     @SWG\Schema(
 *       @SWG\Property(
 *         property="id",
 *         type="object",
 *         @SWG\Property(
 *           property="abc",
 *           type="object",
 *           @SWG\Property(
 *             property="inner abc",
 *             type="number",
 *             default=1,
 *             example=123
 *           )
 *         ),
 *         @SWG\Property(
 *           property="xyz",
 *           type="string",
 *           default="xyz default value",
 *           example="xyz example value",
 *         )
 *       )
 *     )
 *   ),
 *   @SWG\Response(
 *     response=200,
 *     description="Details of the customer"
 *   ),
 *   @SWG\Response(
 *     response=400,
 *     description="Email required"
 *   ),
 *   @SWG\Response(
 *     response=404,
 *     description="Customer does not exist"
 *   ),
 *   @SWG\Response(
 *     response="default",
 *     description="an ""unexpected"" error"
 *   )
 * )
 */
/**

The output is as below

  

注意:我正在开发一个需要原始PHP的项目,但仍然如此   想用Swagger。因此,我使用了这个而不是创建模型   制作嵌套参数的技术。

编辑1:我不知道问题是什么,UI是预期的,但在发出请求时,帖子或有效负载中没有数据。

编辑2:转换为发布。 适用于file_get_contents("php://input")