【问题标题】:Swagger PHP - how to define a nested property?Swagger PHP - 如何定义嵌套属性?
【发布时间】:2016-09-17 11:18:52
【问题描述】:

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

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

{
"id": 1,
"status": "published",
"gps": {
    "lat": "0.00000000",
    "lng": "0.00000000"
}

idstatus 很容易定义,但是gps 是一个问题,因为没有单独的类来定义它,它是模型内部的一个数组。是否可以在不必创建虚拟类的情况下定义此数组?

当前模型文件中的cmets:

/**
 * @SWG\Definition(@SWG\Xml(name="Event"))
 */
 class Event extends BaseModel {
     /**
     * @SWG\Property(
     *      property="id",
     *      type="integer",
     *      example="103"
     * )
     * @SWG\Property(
     *      property="status",
     *      type="string",
     *      enum={"published", "draft", "suspended"}
     *      example="published"
     * )
     */

 }

【问题讨论】:

    标签: php swagger-php


    【解决方案1】:

    遇到完全相同的问题,今天解决了!

    这是 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:将 Get 转换为 Post。 与file_get_contents("php://input") 一起工作正常

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多