Object Swagger 中的对象

Object within Object Swagger

我正在使用 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;

}

配置:

终于找到了解决办法:

这将在Pull Request on Github

中解决