我使用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;
}
配置: