Object Swagger中的对象

时间:2018-03-19 16:24:07

标签: php swagger nelmioapidocbundle

我使用NelmioApiDocBundle和Swagger来描述我的API。

我想描述包含另一个对象的响应对象:

例如 - json str:

"Person": {
    "firstname": "John",
    "lastName": "Smith",
    "car": {
       "brand": "Tesla",
       "price": "1000"
    }
}

我的PHP看起来像:

use Swagger\Annotations as SWG;

class Person {

    /**
     * @SWG\Property(
     *     title="firstName",
     *     type="string",
     *     required={"true"},
     *     description="Last Name"
     * )
     */
    protected $firstName;
    /**
     * @SWG\Property(
     *     title="lastName",
     *     type="string",
     *     required={"true"},
     *     description="First Name"
     * )
     */
    protected $lastName;        
    /**
     * @SWG\Property(
     *     title="data",
     *     required={"true"},
     *     description="The fetched article",
     *     type="object", <- THAT IS THE PROBLEM
     *     @SWG\Property(property="Car", type=Car::class)
     * )
     */
    protected $car;
}

class Car {

    /**
     * @SWG\Property(
     *     title="brand",
     *     type="string",
     *     required={"true"},
     *     description="brand"
     * )
     */
    protected $brand;
    /**
     * @SWG\Property(
     *     title="price",
     *     type="string",
     *     required={"true"},
     *     description="price"
     * )
     */
     protected $price;

}

配置:

  • php:&#34; 7.1.7&#34;
  • nelmio / api-doc-bundle:&#34; 3.0&#34;
  • symfony / symfony:&#34; 3.4.0&#34;,
  • zircote / swagger-php&#34;:&#34; 2.0&#34;

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案:

这将在此Pull Request on Github

中解决